views:

677

answers:

2

Here's my setup: a Mac, running OS X Tiger. Windows XP running in a virtual machine (Parallels). Windows XP has my Mac home directory mapped as a network drive.

I have two files in a directory of my Mac home directory:

foo.py

pass

test.py

import foo

If I run test.py from within my virtual machine by typing 'python test.py', I get this:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import foo
ImportError: No module named foo

If I try to import foo from the console (running python under Windows from the same directory), all is well:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>>

If I run test.py with Mac python, all is well.

If I copy test.py and foo.py to a different directory, I can run test.py under Windows without problems.

There is an init.py in the original directory, but it is empty. Furthermore, copying it with the other files doesn't break anything in the previous paragraph.

There are no python-related environment variables set.

Any ideas?

+2  A: 

Add import sys; print sys.path to the start of test.py. See what it prints out in the failing case. If "." isn't on the list, that may be your problem.

fivebells
'.' is not on the list, but the CWD is the first entry (which I assume is an expanded '.').
John Fouhy
I up-modded, but in general the executed module's directory is always added to pythopath. CWD is not always added. In this case, seems CWD and module's directory are the same thing, so it's not relevant.
Ali A
+1  A: 

As a random guess: are the permissions on foo.py accessable from the windows client? (eg try opening with notepad from the virtual machine).

If that's OK, try running:

python -v -v test.py

and looking at the output (alternatively, set PYTHONVERBOSE=2). This should list all the places it tries to import foo from. Comparing it with a similar trace on the working machine may give some further clues.

Brian
The permissions seem fine (from both sides). 'python -v -v test.py' shows that it's not looking in sys.path[0]; otoh if I just run 'python -v -v' and then type 'import foo' at the prompt, it finds it the first place it looks.
John Fouhy
Thats strange. I can't think of anything that would cause it to skip an entry in sys.path (especially if acting differently when interactive). The only approach I can think of is to try to narrow down the causes (eg. can it be reproduced on other network drives, or after removing the __init__.py )
Brian