domingo, 15 de enero de 2012

Confusing python path2

Lets clear things up:

I want to add a path to PYTHONPATH so Python doesn't complain about not finding a module(a library)/cannot import a module. 
From my terminal emulator(console, terminal)
$user: export PYTHONPATH=$PYTHONPATH:/path/to/my/module
From inside a python module
import sys
sys.path.append('path/to/my/module')

I want python to always find this or that module
$user: gedit ~/.bashrc
export PYTHONPATH=$PYTHONPATH:/path/to/my/module
Or
From the first file.py you run
import sys
sys.path.append('path/to/my/module')

This is different that then system PATH
This other path is used to find binaries/executables in your console/terminal emulator. You modify this other path using:
export PATH=$PATH:/path/to/a/binary
So you can run your shiny new binary/executable like this
$user: binary


And if you want to modify this path from inside python you do:
import os.environ['PATH'] += ':/new/path'
This only affects the current session and its practically useless unless you are doing some weird bash inside python stuff. Remember that you use : to separate paths.

No hay comentarios:

Publicar un comentario