module name not recognized

Darren Dale dd55 at cornell.edu
Sun Oct 10 13:06:47 EDT 2004


Fredrik Lundh wrote:

> Darren Dale wrote:
> 
>>I have built two basic modules using distutils. One of them installs fine,
>> but the other, I can't import modules from it. I've been pouring over the
>> code and I cant find the problem.
>>
>> I know the file has been copied to site-packages/mypackage, but I cant do
>>
>> from mypackage import mymodule
> 
> really?  do you mean that you could type that into your mail program, but
> not into a Python program?  that's weird... (read on)
> 
>> Could I get suggestions as to why a module would be installed but not
>> registered?
> 
> if you run python with the -vv option, it tells you where it looks.
> 
>     $ python -vv
>     ...
>     >>> from mypackage import mymodule
>     # trying mypackage.so
>     # trying mypackage.py
>     # trying mypackage.pyc
>     ...
> 
> btw, note that if that import finds a mypackage without a mymodule,
> it says
> 
>     ImportError: cannot import name mymodule
> 
> if it cannot find mypackage itself, it says
> 
>     ImportError: No module named mypackage
> 
> (this is why you should *always* include tracebacks when asking about
> an error...  "can't do" or "doesn't work" or "an error" or even "an import
> error" doesn't contain all the information you have, so you're forcing us
> to
> guess.  don't do that, if you can avoid it)
> 
> </F>

Sorry, I thought the subject line would be enough information. You are
right. The relevant ouput from python -vv is below. Distutils installed the
package to /usr/lib/python2.3/site-packages/simCTR, but python is looking
only in the directory of my test script:


# trying /home/darren/temp/simCTR/fresnel.so
# trying /home/darren/temp/simCTR/fresnelmodule.so
# trying /home/darren/temp/simCTR/fresnel.py
# trying /home/darren/temp/simCTR/fresnel.pyc
Traceback (most recent call last):
  File "temp.py", line 7, in ?
    from simCTR.fresnel import *
ImportError: No module named fresnel


Why doesnt python check in /usr/lib/python2.3/site-packages/simCTR? It does
so for the other package I built. Here is the contents of the
site-packages/simCTR directory:

-rw-r--r--  1 root root  1248 Oct 10 12:56 __init__.py
-rw-r--r--  1 root root  1952 Oct 10 12:56 __init__.pyc
-rw-r--r--  1 root root  7805 Oct  8 16:00 fresnel.py
-rw-r--r--  1 root root  8062 Oct 10 12:51 fresnel.pyc
-rw-r--r--  1 root root 10235 Oct  8 16:00 kinematic.py
-rw-r--r--  1 root root 14011 Oct 10 12:51 kinematic.pyc
-rw-r--r--  1 root root  3795 Oct  5 12:53 spaceGroups.py
-rw-r--r--  1 root root  4381 Oct 10 12:51 spaceGroups.pyc


Thanks,
Darren




More information about the Python-list mailing list