How to set pythonpath in Mac OS X?

Russell E. Owen no at spam.invalid
Fri Oct 24 17:46:40 EDT 2003


In article <mailman.69.1066987239.702.python-list at python.org>,
 Eric Wichterich <eric.wichterich at gmx.de> wrote:

>Hello Pythonistas,
>
>I am trying to get certain (self-written) libraries imported into my 
>scripts using statements like
>
>"from library import function.py".
>
>But they are not being found.
>
>I think that the pythonpath-variable must be expanded to the location 
>to this libraries.
>
>But, I can't find any usable information using Google on how to set up 
>the pythonpath properly.
>I don't even know where to look for the pythonpath-variable?
>
>It would be great if anyone could help me out on this?

You can define the environment variable PYTHONPATH to include any paths 
you like, and python will read this info when it starts up.

On MacOS X you have several choices for defining environment variables. 
All work for unix command-line apps, but only can be seen by GUI apps, 
so it's the one I recommend you use: put the information into a file 
.MacOSX/environment.plist (which you will probably have to create). 
Instructions are available at 
<http://www.astro.washington.edu/owen/AquaEnvVar.html>

If you only care about command-line usage then you can edit ~/.cshrc and 
include a command such as
setenv PYTHONPATH "/path/one/:path/two:..."
(note: .cshrc may not be the best choice, but it certainly works).

Warning: do NOT mix these two techniques. At least in Jaguar, 
environment.plist completely overrides env variables defined or modified 
in .cshrc.

-- Russell




More information about the Python-list mailing list