Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named lxml - Even though LXML Is installed

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

Edit: More detail 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?

like image 826
Michael Romrell Avatar asked Nov 19 '14 03:11

Michael Romrell


2 Answers

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}"

like image 89
Michael Romrell Avatar answered Sep 27 '22 18:09

Michael Romrell


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

like image 45
jerome wong Avatar answered Sep 27 '22 18:09

jerome wong