13

I'm getting this error "ImportError: No module named lxml" Even though LXML Is definitely installed. Specifically it's installed within the python Virtualenv for the project. and ultimately I'm working on the Python/Amazon Product API. I get the error after trying to run one of the example scripts for that project from the terminal (mac).

How can I fix this? or further track down the issue?

Google searching lead me to:

  • Reintsall LXML
  • Ensure Xcode license was agreed to: sudo xcodebuild -license
  • Updating LXML with: pip install --upgrade lxml Currently at ver 3.4.0
  • reinstalled LXML dependencies as outlined here - pip install libxml2-dev libxslt-dev python-dev

The line of code throwing the error is from lxml import etree, objectify, this is in a folder far away from where LXML is installed in my virtual environment (although I am running the script from within my virtualenv in terminal). If the issues is simply a matter of the script not knowing where to find the LXML install, how would I fix that?

starball
  • 20,030
  • 7
  • 43
  • 238
Michael Romrell
  • 1,026
  • 5
  • 15
  • 31
  • What happens when you run python from a command prompt and try `import lxml`? –  Nov 19 '14 at 04:24

3 Answers3

9

It turns out that I found my answer here: import lxml fails on OSX after (seemingly) successful install

Apparently, LXML Install on a Mac ends up installing it in the wrong path, so you have to reset the path using: export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

Community
  • 1
  • 1
Michael Romrell
  • 1,026
  • 5
  • 15
  • 31
  • You are allowed (in fact are encouraged) to accept your own answers. There is even a badge for doing so. –  Nov 19 '14 at 23:23
  • Hello, I got the same error but after edit bash_profile and Path I still got the same error. It is not fix. Could you tell more detail how to put that line to which place please ? – user1314404 Mar 30 '16 at 08:49
  • 1
    I think I got the answer here: http://stackoverflow.com/questions/10729116/adding-a-module-specifically-pymorph-to-spyder-python-ide – user1314404 Mar 31 '16 at 14:34
3

So it turns out that if you're using python via homebrew, things get a little sketchy with apps like Inkscape that have it hardcoded in their mind that a certain version of python is needed.

Getting the right python version was simply uninstalling brew & installing PIP:

brew uninstall --ignore-dependencies python

sudo easy_install pip

STATIC_DEPS=true sudo pip install lxml

Andrew Lazarus
  • 989
  • 2
  • 16
  • 25
3

if your python is python 3.6, try pip3.6 install lxml