[Pythonmac-SIG] import question

Bob Ippolito bob at redivi.com
Thu Nov 6 14:37:02 EST 2003


On Nov 6, 2003, at 1:48 PM, Scott Frankel wrote:

>
> Apologies in advance if this is so simple as to be OT ...
>
> How should I setup the PYTHONPATH var on OSX so that I can
> import a module I've built to another script?
>
> i.e.:
> I've built a module and installed it in /usr/local/my_stuff/py_modules
> I've set the PYTHONPATH environment var in my 
> ~/Library/init/tcsh/rc.mine
> 	setenv PYTHONPATH /usr/local/my_stuff/py_modules
> Then sourced rc.mine.
>
> From my script, I get an "ImportError: no module named foo" from this
> 	import foo
> which exists and is executable in /usr/local/my_stuff/py_modules.

IMHO, PYTHONPATH is a crutch and should rarely be used.  What you 
should do, for most situations, is to create "pth" files in your 
existing sys.path .. for example, in my /Library/Python/2.3, I have a 
file aeve.pth which contains (only) the following text 
"/Users/bob/svn.undefined.org/aeve" sans quotes.  What this means, is 
when the python interpreter starts (if it finds site.py, of course, 
which is almost all the time) it will add 
/Users/bob/svn.undefined.org/aeve to sys.path and find any 
modules/packages in that directory.

-bob




More information about the Pythonmac-SIG mailing list