5

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.

entrepaul
  • 927
  • 3
  • 12
  • 23

3 Answers3

2

If you put the second method in your shell's init file, you should be fine. (for example, ${HOME}/.bashrc)

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • with a text editor?. Alternatively (in a shell), `echo 'export PYTHONPATH=${PYTHONPATH}:foo/bar' >> ${HOME}/.bashrc` should work too. (Note the changes won't take effect until the next time you restart your shell) – mgilson Sep 08 '12 at 20:24
1

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

Peter Hanley
  • 1,254
  • 1
  • 11
  • 19
1

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.

wrongite
  • 898
  • 1
  • 13
  • 23