Dick Moores wrote:
> Thanks, Kent.
> 
> At 05:40 AM 9/2/2007, Kent Johnson wrote:
>> 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.
> 
> You mean such as site-packages\mine? That was working until I tried 
> blanking PYTHONPATH, which previously contained
> E:\Python25\lib\site-packages\mine\

You need to be clear on the difference between a module and a package.

A module is a single python file, imported by its name.
A package is a directory containing python files. The package dir must 
contain a file named __init__.py, which signals to Python that the dir 
is a package. Modules within a package are imported by 
packagename.modulename.

This might help:
http://docs.python.org/tut/node8.html

If you put site-packages\mine\ in PYTHONPATH, you are telling Python to 
look inside mine\ for modules and modules are imported by their simple name.

If you just put mine\ in site-packages, you are saying that mine is a 
*package* so it must contain __init__.py and modules within it will be 
imported by compound name mine.mymodule.
> 
>> - add a .pth file to site-packages/ that contains the path to the 
>> dir you want to add to sys.path
> 
> I tried this with no PYTHONPATH. I put pointers.pth in site-packages\ 
> with the single line, E:\PythonWork\Functions\ . Functions\  contains 
> functions.py . However,
>  >>> import functions
> Traceback (most recent call last):
>    File "<input>", line 1, in ?
> ImportError: No module named functions

Don't know why this didn't work. Does the Functions dir appear on sys.path?

> I also tried putting an __init__.py in Functions\
>  >>> from Functions import functions
> Traceback (most recent call last):
>    File "<input>", line 1, in ?
> ImportError: No module named Functions

In this case E:\PythonWork\ should be in sys.path so the *package* 
Functions will be found.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to