How do I define the search path for personal library

Peter Hansen peter at engcorp.com
Sun Dec 19 00:10:29 EST 2004


les_ander at yahoo.com wrote:
> Dear all,
> i have a simple question.
> Suppose I have my classes such as
> myClass1.py
> myClass2.py
> etc
> which I keep in a special folder ~/py_libs
> 
> Now
> suppose I have a program that is not in py_libs
> but I want to do
> import myClass1 # note: myClass1 is not in the current directory
> 
> how can I set the search path for python so that it can
> find myClass1?

There are several options, including the PYTHONPATH environment
variable, creating a .pth file in site-packages or somewhere
(as documented in http://www.python.org/doc/2.4/lib/module-site.html),
or even creating your own sitecustomize.py file (also documented
in the site.py module docs).

What is best depends a bit on your own environment and needs.
For example, do you just want this available at the interactive
prompt, or to all code you write, or to code that other users
on the same system will write?

-Peter



More information about the Python-list mailing list