By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,503 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,503 IT Pros & Developers. It's quick & easy.

How do I define the search path for personal library

P: n/a
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?
thanks

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
le*******@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
Jul 18 '05 #2

P: n/a
If i understand correctly what you're after I think another option is

import sys
sys.path.append('<your choice of path here')

regards

richard.

Jul 18 '05 #3

P: n/a
Yes, this is exactly what I wanted--just like in perl I can add search
path to @inc.

thanks

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.