tags:

views:

280

answers:

4

I am running Cygwin Python version 2.5.2.

I have a three-line source file, called import.py:

#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"

When I execute "python import.py", it works:

C:\Temp>python import.py
Success!

When I run the python interpreter and type the commands, it works:

C:\Temp>python
Python 2.5.2 (r252:60911, Dec  2 2008, 09:26:14)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/python
... import xml.etree.ElementTree as ET
>>> print "Success!"
Success!
>>>

But when I execute "import.py', it does not work:

C:\Temp>which python
/usr/bin/python

C:\Temp>import.py
Traceback (most recent call last):
  File "C:\Temp\import.py", line 2, in ?
    import xml.etree.ElementTree as ET
ImportError: No module named etree.ElementTree

When I remove the first line (#!/usr/bin/python), I get the same error. I need that line in there, though, for when this script runs on Linux. And it works fine on Linux.

Any ideas?

Thanks.

A: 

Try:

./import.py

Most people don't have "." in their path.

just typing python will call the cygwin python.

import.py will likely call whichever python is associated with .py files under windows.

You are using two different python executables.

Turtle
+1  A: 

Probably py extension is connected to some other python interpreter than the one in /usr/bin/python

Tuomas Pelkonen
A: 

Create a batch file next to your program that calls it the right way ... and I'm fairly sure you've got the problem because of an ambiguity between "windows python" (a python interpreter compiled for windows) and "cygwin python" (a python interpreter running on cygwin).

maligree
+3  A: 

I have the feeling that

C:\Temp>import.py

uses a different interpreter. Can you try with the following scripts:

#!/usr/bin/env python
import sys
print sys.executable
import xml.etree.ElementTree as ET
print "Success!"
krawyoti
You are correct.This script reveals that the .py extension is associated with the Python interpreter at c:\Python-2.3.3\python.exe, which does not have the xml.etree.ElementTree module in it.The "python" executable in the path is c:\cygwin\bin\python.exe, which is version 2.5.2, which does have the xml.etree.ElementTree built in.Thanks!
Martin Del Vecchio
+1 thou' I dont use Python on Windows, this is definitely something I'll keep in mind. Thanks.
jeffjose