module name not recognized

D

Darren Dale

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

Could I get suggestions as to why a module would be installed but not
registered?

Thanks,
Darren
 
L

Larry Bates

Darren said:
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

Could I get suggestions as to why a module would be installed but not
registered?

Thanks,
Darren

Two things to check:

Does the package have the required __init__.py file?
Is the directory where it is installed on the PYTHONPATH?

Larry Bates
 
D

Darren Dale

Larry said:
Two things to check:

Does the package have the required __init__.py file?
Is the directory where it is installed on the PYTHONPATH?

Larry Bates

Thanks Larry,
I checked both before writing the original post, this isnt the problem.
 
J

Jeffrey Froman

Darren said:
Could I get suggestions as to why a module would be installed but not
registered?

If the permissions are incorrect on the module files, then some users may be
unable to import the modules.

Jeffrey
 
A

Alan Kennedy

[Darren Dale]
[Larry Bates]
[Darren Dale]
> I checked both before writing the original post, this isnt the
> problem.

One more thing to check: have you named your module with an identical
name to an existing module that is before your module the path, e.g.
calling your module "xml" or "email", which clash with standard
library modules. This is a frequent cause of hair-pulling inexplicable
behaviour.

If that isn't the problem either, then you're probably best off
posting more details, i.e. what are your modules called, where are
they located, what doesn't work/what exceptions are raised, etc.

regards,

alan.
 
F

Fredrik Lundh

Darren said:
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
... # 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>
 
D

Darren Dale

Fredrik said:
really? do you mean that you could type that into your mail program, but
not into a Python program? that's weird... (read on)


if you run python with the -vv option, it tells you where it looks.

$ python -vv
...
# 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
 
D

Darren Dale

Darren said:
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

Could I get suggestions as to why a module would be installed but not
registered?

Thanks,
Darren


Here is some more information. I tried changing the name of my package. It
was called simCTR, and stored in the simCTR directory, and installed
accordingly by distutils. import statements fail because the directory of
my test script is searched during the import request, but the site-packages
directory is not.

I renamed the package to simctr, installed, and the import statements
succeed. I didnt want to make this name change permanent, so I deleted the
site-packages/simctr directory, tried to install simCTR again, and it
fails.

/usr/lib/python2.3/site-packages/simCTR:
total 64
-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

/usr/lib/python2.3/site-packages/simctr:
total 64
-rw-r--r-- 1 root root 1248 Oct 10 13:17 __init__.py
-rw-r--r-- 1 root root 1952 Oct 10 13:19 __init__.pyc
-rw-r--r-- 1 root root 7805 Oct 10 13:17 fresnel.py
-rw-r--r-- 1 root root 8062 Oct 10 13:19 fresnel.pyc
-rw-r--r-- 1 root root 10235 Oct 10 13:17 kinematic.py
-rw-r--r-- 1 root root 14011 Oct 10 13:19 kinematic.pyc
-rw-r--r-- 1 root root 3795 Oct 10 13:17 spaceGroups.py
-rw-r--r-- 1 root root 4381 Oct 10 13:19 spaceGroups.pyc


Thanks,
Darren
 
R

Robert Kern

Darren said:
# 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

Don't execute python from /home/darren/temp .

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
D

Darren Dale

Robert said:
Don't execute python from /home/darren/temp .

I see. I had two problems. I didnt realize there was an old simCTR directory
in ~/temp. Python was searching this directory, and when it didnt find the
module it raised an error. I read that python would try the current
directory first, and if that failed it would try other places along the
python search path. The caveat is that if python finds a package but not
the module, it will not continue the search. Thank you everyone, especially
Robert and Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top