[Tutor] how to permanently add a module path

Christopher Arndt chris.arndt at web.de
Fri Dec 22 17:07:27 CET 2006


shawn bright schrieb:
> lo there,
> 
> i am working with python in ubuntu, my app has some modules that i would
> like to import from anywhere.
> i can sys.path.append(my_module_dir)    but it only lasts as long as
> that python session.
> how can i add a directory to the import path permantly

http://article.gmane.org/gmane.comp.python.tutor/36916

See point 2)


Addendum:

To set the PYTHONPATH environment variable:

Windows: "Control panel/System/Advanced/Envirnment..." or something similar and
change/add value of PYTHONPATH (entries are separated by semicolons ';')

Linux:

Depends on your distribution:

- Standard way would be to edit ~/.bash_profile and add e.g.

# entries are separated by colons ':'
PYTHONPATH=$HOME/lib/python:/where/my/other/python/modules/live
export PYTHONPATH

but not all desktop environment read this file.

- On Debian, for the system wide environment, you can add the same snippet to
/etc/environment or add a file with the same contents to /etc/profile.d


HTH, Chris


More information about the Tutor mailing list