How do I define the search path for personal library

Peter Hansen peter at
Sun Dec 19 06:10:29 CET 2004

les_ander at wrote:
> Dear all,
> i have a simple question.
> Suppose I have my classes such as
> 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,
or even creating your own file (also documented
in the 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?


More information about the Python-list mailing list