Hi there,
I have Python related issue within TextMate. I am trying to start Python script directly from TextMate, but it fails.
Here comes the output from Terminal:
michalo:/Users/michalo/test> python simple.py One Two michalo:/Users/michalo/test> cat simple.py #!/usr/bin/python
import xml.etree.ElementTree as ET
def main(): element = ET.XML("<root><child>One</child><child>Two</child></root>") for subelement in element: print subelement.text
if __name__ == "__main__": # Someone is launching this directly main()
michalo:/Users/michalo/test> python simple.py One Two michalo:/Users/michalo/test> python --version Python 2.6.1
However, if I use Python bundle to start this script directly from the TextMate (Bundles -> Python -> Run script) I get following error:
ImportError: 'No module named etree.ElementTree'
module body in xml.py at line 3 import xml.etree.ElementTree as ET copy output Program exited with code #1 after 0.19 seconds.
If I start it from TextMate Bundles -> Python -> Run script (Terminal)), I am getting following error:
Traceback (most recent call last): File "/Users/michalo/Documents/work_files/public/notes/python/xml.py", line 3, in <module> import xml.etree.ElementTree as ET File "/Users/michalo/Documents/work_files/public/notes/python/xml.py", line 3, in <module> import xml.etree.ElementTree as ET ImportError: No module named etree.ElementTree michalo:/Users/michalo/Documents/work_files/public/notes/python>
Do you know what can be the source of the issue?
That's what I get from the Terminal windows (when I try to get Python version):
michalo:/Users/michalo/test> which python /usr/bin/python michalo:/Users/michalo/test> python --version Python 2.6.1 michalo:/Users/michalo/test>
And you can find attached screen shoot from text mate. I have created simple text file:
which python python --version
And executed it with: Bundles -> Shell Scripts -> Run script
Does anyone have an idea what's wrong here?
Cheers
Michal
On 1 Jan 2011, at 19:02, michal owsiak wrote:
[…] if I use Python bundle to start this script directly from the TextMate (Bundles -> Python -> Run script) I get following error:
ImportError: 'No module named etree.ElementTree'
That is weird, as the script works for me (with ⌘R).
Try type ‘env|sort’ in a new (TextMate) document and press ⌃R. This dumps all environment variables.
Do the same in Terminal and see if there are any noticable differences. I am not familiar with how the environment can affect Python search paths, only know of the site_customize thing, but perhaps this is key?
Also try create a new account on your machine and run the script from there (in TextMate). That is a quick way to find out if the problem is local.
On Jan 2, 2011, at 2:17 PM, Allan Odgaard wrote:
I am not familiar with how the environment can affect Python search paths, only know of the site_customize thing, but perhaps this is key?
The PYTHONPATH environment variable can also affect this, but it will only add to the directories that are already being searched, so something available by default (like the xml module) should still work. I have PYTHONPATH defined in the TextMate preferences, and the example script works for me as well.
One thing that comes to mind: The “Run Script” command in the Python bundle uses some logic to figure out where the `python` executable is. I believe it is completely ignoring `#!/usr/bin/python` on the first line of your script. Could it be finding another copy of Python elsewhere on your system?
I would try “running” each of these from within TextMate (type it on a line and hit ⌃R) and see what you get.
echo $TM_PYTHON
and
which python