Importing package on Windows XP

M

M.-H. Z

Hello dear Python hackers.
I have a pretty stupid problem that I cannot solve despite all my
efforts: Python cannot find my modules. I am sure the answer is
obvious, but I cannot find it.
The problem is simple, here is a toy example (which does not work).
I have a file:
---
import sys
print sys.path
import module2
import mod.module1
if __name__ == "__main__":
print "OK"
---
I have something like
---
print "I am in module X"
---
for the files moduleX.py.
The file hierarchy is the following:
"." (which is "C:\Documents and Settings\Administrateur\Bureau\Test")
contains "test.py" (the main file), "module2.py", "module2.pyc" and
the directory "mod". This directory contains "__init.py__" (empty) and
"module1.py".
I put the current path (again: "C:\Documents and Settings
\Administrateur\Bureau\Test") into the PYTHONPATH environment variable
(using "set" and the Control Panel) and I added the path into the
PythonPath registers (just in case).
The output of the execution still is:
---
['C:\\Documents and Settings\\Administrateur\\Bureau\Test', ...]
I am in module 2
Traceback (most recent call last):
File "test.py", line 6 in (module)
from mod import module
ImportError: No module named mod
---
I really do not know where the error is. It works perfectly well under
Linux and Mac.
Could anyone help me there?
Thanks a lot,
Matthias.
 
M

M.-H. Z

Darn! That was it!
I was pretty stupid!
I swear I will stop drinking vodka before 8am.
However, it does not solve the problem on my main project (which was
not this toy example of course), since the names were correct there.
Keep on working.
Thanks a lot, Peter, for reading my long post and helping me.
Matthias.
 
D

Dave Angel

M.-H. Z said:
Hello dear Python hackers.
I have a pretty stupid problem that I cannot solve despite all my
efforts: Python cannot find my modules. I am sure the answer is
obvious, but I cannot find it.
The problem is simple, here is a toy example (which does not work).
I have a file:
---
import sys
print sys.path
import module2
import mod.module1
if __name__ == "__main__":
print "OK"
---
I have something like
---
print "I am in module X"
---
for the files moduleX.py.
The file hierarchy is the following:
"." (which is "C:\Documents and Settings\Administrateur\Bureau\Test")
contains "test.py" (the main file), "module2.py", "module2.pyc" and
the directory "mod". This directory contains "__init.py__" (empty) and
"module1.py".
I put the current path (again: "C:\Documents and Settings
\Administrateur\Bureau\Test") into the PYTHONPATH environment variable
(using "set" and the Control Panel) and I added the path into the
PythonPath registers (just in case).
The output of the execution still is:
---
['C:\\Documents and Settings\\Administrateur\\Bureau\Test', ...]
I am in module 2
Traceback (most recent call last):
File "test.py", line 6 in (module)
from mod import module
ImportError: No module named mod
---
I really do not know where the error is. It works perfectly well under
Linux and Mac.
Could anyone help me there?
Thanks a lot,
Matthias.
Probably the error is that you're not posting the same code as you're
executing. The error message refers to a line:
from mod import module

which is wrong in two ways. But in your source, you show
import mod.module1

which I expect should work. (I didn't try it)


So run the source you posted, and if it still fails, show us the
traceback from that same code. Then somebody will spot the problem.

HTH
DaveA
 
M

M.-H. Z

Dear Dave,
You are absolutely right!
I changed my code so many times that I got confused when writing the
post.
Actually, I tried "from mod import module1" and "import mod.module1".
Of course, they led to the same error: the one that Peter pointed.
Anyway, thanks a lot for your help!
Matthias.
(Yet, I did not find the mistake in my project... But I still cannot
precisely locate it from whole lot of modules that I use.)
 
M

M.-H. Z

Problem solved!
For those who wish to know, the actual problem was the following.
In my project, I had a package called "parser". I works fine on Linux
and Mac, but seems to conflict with other package on Windows.
So the module I wanted to load was not found. I had to rename the
package name...
D'oh!
Thanks again to those who helped me.
Matthias.
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top