Reputation: 947
I attempted the two commonly mentioned methods below, and they have not worked - hence this [seemingly redundant] question.
import sys
sys.path.append('foo/bar')
AND
export PYTHONPATH=$PYTHONPATH:foo/bar
The first one terminates the append once interpreter is exited. The second terminates when terminal is closed (despite the fact that people seem to have no problem with permanently appending via the second method).
What am I missing here and how do I resolve this issue?
Thank you.
Upvotes: 5
Views: 13293
Reputation: 918
I suggest to use export PYTHONPATH=foo/bar:$PYTHONPATH
if you prefer your custom library to be found before the default if they have the same name.
Upvotes: 1
Reputation: 1284
PYTHONPATH is a system wide variable, so it has to be set up in a more permanent way (basically, that export PYTHONPATH=$PYTHONPATH:foo/bar
needs to be executed automatically by whatever shell is then executing python) - os specific instructions are below:
Windows: http://docs.python.org/using/windows.html#excursus-setting-environment-variables
Mac/Unix: http://users-cs.au.dk/chili/PBI/pythonpath.html
Upvotes: 1
Reputation: 309929
If you put the second method in your shell's init file, you should be fine. (for example, ${HOME}/.bashrc
)
Upvotes: 2