[Tutor] problem resulting from installing 3.0

Kent Johnson kent37 at tds.net
Sun Sep 2 14:40:53 CEST 2007

Dick Moores wrote:
> At 01:08 AM 9/1/2007, Alan Gauld wrote:
>> "Dick Moores" <rdm at rcblue.com> wrote
>> > > > And another question is, exactly what should go into PYTHONPATH?
>> >
>> > >Its what goes into sys.path.

PYTHONPATH is for your own customizations of sys.path, it is not the 
entirety of sys.path. AFAIK you don't have to define it at all if you 
don't want to use it.

If you have a dir containing modules that you want to be able to import 
directly, e.g.

and in code you want to say
import util, foo

then put /path/to/mine/ in PYTHONPATH.

If you have a package - a dir of modules that go together, that you want 
to import as a package, e.g.

then you import them as
from mine import util

you still put /path/to/mine/ in PYTHONPATH but now it is the dir 
containing the package rather than the dir containing the module.

__init__.py signals to Python that the containing dir should be treated 
as a package. It is independent of PYTHONPATH.

There are quite a few ways to get a module into the search path, 
modifying PYTHONPATH is just one way. Some others:
- create a site-packages/ dir in the Python lib dir. Put your modules 
and packages there and they will be found by Python.
- add a .pth file to site-packages/ that contains the path to the dir 
you want to add to sys.path
- modify sys.path directly in code. You can do this in a specific 
application or you can create site-packages/sitecustomize.py and do 
site-wide customizations there.


More information about the Tutor mailing list