Module import Error Python
Question: I just installed **lxml** for parsing xml file in python. I am using
**TextMate** as an IDE. Problem is that when I try to import lxml `(from lxml
import entree)` then I get

**ImportError** :'No module named lxml'

But when I use **Terminal** then everything is fine

    
    
    Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from lxml import etree
    >>> root=etree.element("root")
    >>> root=etree.Element("root")
    >>> print (root.tag)
    root
    >>> root.append(etree.Element("child1"))
    >>> child2 = etree.SubElement(root, "child2")
    >>> child3 = etree.SubElement(root, "child3")
    >>> print (etree.tostring(root,pretty_print=True))
    <root>
      <child1/>
      <child2/>
      <child3/>
    </root>
    

It's pretty weird. Does it have something to do with TextMate?

Suggestion Please!


Answer: This most probably means that you have more than one python installation on
your system and that TextMate and the Terminal using different ones by
default.

One workaround: In your python file, you can specify an interpreter directive
to point to the python installation (and executable) of your choice:

    
    
    #!/usr/local/bin/python
    # Even thought standard python is in /usr/bin/python, here we want another ...
    

