473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

module name not recognized

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
Jul 18 '05 #1
9 11293
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

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
Jul 18 '05 #2
Larry Bates 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

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


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

Jul 18 '05 #3
Darren Dale wrote:
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
Jul 18 '05 #4
[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.

[Larry Bates]Two things to check:

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

[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.
Jul 18 '05 #5
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>

Jul 18 '05 #6
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

Jul 18 '05 #7
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

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
Jul 18 '05 #8
Darren Dale wrote:
# 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
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #9
Robert Kern wrote:
Darren Dale wrote:
# 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 .


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.
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olivier Vierlinck | last post by:
Hi, I've a python script using somecalls to the abs() built-in function. Now, I have to import a module named 'abs' too... The consequence if that line code like if (abs(a-b) < epsilon:...
2
by: Casey Hawthorne | last post by:
Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name? Like "iskeyword" determines if a word is a keyword! -- Regards, Casey
1
by: John Pass | last post by:
Hi, This is something really simple. A Console Application example in a course book, where the module file name was renamed to Welcome1, works fine when I use the original name "module1" for the...
11
by: Fred | last post by:
I hope someone can help me with the below problem... Thanks, Fred My enviroment: -------------------------- Slackware Linux 10.2 Python 2.4.2 MySql version 4.1.14
3
by: Brahm | last post by:
hey, another question guys.. is there any way to get module name ? E.g: bas_serial_comm.vb Daniel
1
by: alain MONTMORY | last post by:
Hello everybody, I am a newbie to python so I hope I am at the right place to expose my problem..... :-http://www.python.org/doc/2.4.2/ext/pure-embedding.html 5.3 Pure Embedding I download the...
0
by: Ron Adam | last post by:
Is there a function to find a filename from a dotted module (or package) name without importing it? The imp function find_module() doesn't work with dotted file names. And it looks like it may...
0
by: Pradnyesh Sawant | last post by:
Hello, I have a string which in reality is the name of a module to be imported. The name of the class contained in the module also has the same (although with different capitalization). My...
3
by: kwatch | last post by:
What is the condition of module name which is available in 'from .. import ..' statement ? ---------------------------------------- import os print os.path # <module 'posixpath'...
4
by: rlntemp-gng | last post by:
I am trying to dynamically populate the module name in the error message. Currently I populate a variable with hardcoded text: strModuleName = "cmdFlushWorkTables_Click" Per my code below, is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.