Adding Directory to PYTHONPATH

bdupire at seatech.fau.edu.bbs bdupire at seatech.fau.edu.bbs
Wed Jul 12 11:00:03 EDT 2000


Hi Mike...

It depends on the platform you  work on.

If you are using Windows, the best is to create a file "mymodules.pth", as
you mentionned.

Ex: "mymodules.pth" content :
mymodules
c:\My Documents\python\modules
Then the next time a Python interpreter is started, sys.path will have
c:\program
files\python\mymodules and c:\My Documents\python\modules added to it, if
they exist. (check!)

This trick doesn't work on other platforms (QNX for example)

On Windows,the other trick is to modify the registry.
Have a look at
http://www.python.org/windows/python/registry.html

Then if you are on Linux/Unix/QNX you have to modify the PYTHONPATH
environment variable.
You can do that in the .cshrc file , located in your home directory.

Edit the file  .cshrc so that it looks like the following:
##### Set path
set path =  ( . /bin /usr/bin /usr/local/bin /usr/ucb /usr/X11/bin
/old_home/bdupire/Python-1.5.2)
set PYTHONPATH = (/old_home/bdupire/Python-1.5.2/my_prog)

On LINUX (bash shell):
$ export PYTHONPATH=/home/me/python
$ echo $PYTHONPATH
 /home/me/python
$ PYTHONPATH=/home/you/python:$PYTHONPATH
$ echo $PYTHONPATH
/home/you/python:/home/me/python


All of these tricks didn't work for me.. so I have to figure out another
way.
If you compiled Python from the source code, go to ../Python-1.5.2/Modules

Edit the file  'Setup'
In thi file you might find the following :

# Standard path components for test modules
TESTPATH=

Modify this line:
TESTPATH=:my_directory
and you will be able to put your modules in
.../Python-1.5.2/Lib/my_directory



I hope this will help as i am also relatively new to Python.

Benoit

mike at pl.net wrote:

> Hi All !
> Probably been asked before but how do you add a new library module
> directory to PYTHONPATH?
>
> I know you can do it dynamically in Python, but in this case I need to
> have a particular module directory available everytime that Python is
> loaded.
>
> I tried including a .pth file but can't see the new directory when I
> print sys.path
>
> Grateful for any pointers
> Best regards
> Aren't we lucky for having Python!
> Mike
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



More information about the Python-list mailing list