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

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?

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

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

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

Related

"pip install lxml" fails with "Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?" [duplicate]

I'm getting an error Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed? when trying to install lxml through pip.
c:\users\f\appdata\local\temp\xmlXPathInitqjzysz.c(1) : fatal error C1083: Cannot open include file: 'libxml/xpath.h': No such file or directory
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'C:\\Users\\f\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2
I don't find any libxml2 dev packages to install via pip.
Using Python 2.7 and Python 3.x on x86 in a virtualenv under Windows 10.
Install lxml from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml for your python version. It's a precompiled WHL with required modules/dependencies.
The site lists several packages, when e.g. using Win32 Python 3.11, use lxml‑4.9.0‑cp311‑cp311‑win32.whl.
Download the file, and then install with:
pip install C:\path\to\downloaded\file\lxml‑4.9.0‑cp311‑cp311‑win32.whl
I had this issue and realised that whilst I did have libxml2 installed, I didn't have the necessary development libraries required by the python package. Installing them solved the problem:
sudo apt-get install libxml2-dev libxslt1-dev
sudo pip install lxml
Try to use:
easy_install lxml
That works for me, win10, python 2.7.
On Mac OS X El Capitan I had to run these two commands to fix this error:
xcode-select --install
pip install lxml
Which ended up installing lxml-3.5.0
When you run the xcode-select command you may have to sign a EULA (so have an X-Term handy for the UI if you're doing this on a headless machine).
In case anyone else has the same issue as this on
Centos, try:
yum install python-lxml
Ubuntu
sudo apt-get install -y python-lxml
worked for me.
set STATICBUILD=true && pip install lxml
run this command instead, must have VS C++ compiler installed first
https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/
It works for me with Python 3.5.2 and Windows 7
I tried install a lib that depends lxml and nothing works. I see a message when build was started: "Building without Cython", so after install cython with apt-get install cython, lxml was installed.
I had this issue and realized that while I did have libxml2 installed, I didn't have the necessary development libraries required by the python package.
1) Installing them solved the problem:
The site to download the file: Download
2) After Installing the file save it in a accessible folder
pip install *path to that file*
For some reason it doesn't work in python 3.11, but 3.10 works.
On windows, to install a module with a previous version, use
py -3.10 -m pip install lxml
if you want to install it in a venv, then use
py -3.10 -m venv .venv
.venv/Scripts/pip.exe install lxml
if you've set up the venv, then you can just use
pip install lxml
You also need to run the python program with that version. If you set up a venv, then you don't need to do this.
py -3.10 file.py
It is not strange for me that none of the solutions above came up, but I saw how the igd installation removed the new version and installed the old one, for the solution I downloaded this archive:https://pypi.org/project/igd/#files
and changed the recommended version of the new version: 'lxml==4.3.0' in setup.py
It works!
I got the same error for python 32 bit. After install 64bit, the problem was fixed.
I am using venv.
In my case it was enough to add lxml==4.6.3 to requirements.txt.
One library wanted earlier version and this was causing this error, so when I forced pip to use newest version (currently 4.6.3) installation was successful.

How to install python packages from CMD?

I want to install urllib2 and JSON but it doesn't seem to let me. I tried using pip install in cmd which didn't work and also tried specifying the Scripts path and then doing the command but that does not work either. I am on 64-bit and I have used some command in pip like pip install python3 (package name) which worked for me but I haven't install anything in some time so I don't remember what the command was exactly that worked for me.
Both of those should be apart of the standard library so there shouldn't be a need to reinstall using pip. Try reinstalling python3 (uninstall then reinstall) and check the "add to path" button at the bottom of the installer before installation.
You can also try pip3 install (package name) and also try to update it to the latest version using simocat's answer
Edit: I believe you don't need to install these packages they come as part of python 3.x
Have you tried using the command pip install (package name)?
You can also try to upgrade pip to the latest version with pip install --upgrade pip and then install a package.
EDIT:
Please note that The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. There is no need to install urllib2. Just import urllib.request into your script
What does:
python -m ensurepip --upgrade
in cmd respond?
(It is always helpful to post the Error output you receive from your commandline) and on these kinds of topics in general you may check: https://stackexchange.com/
Btw. Here is a related q&a:
Installing pip on windows?

Trouble installing packages in the wrong Python version

I'm having problems while installing a new package in Python. I was looking for the termcolor package. I installed it using the apt:
sudo apt-get install python-termcolor
But when I try to use it in Python 3.6 it keep telling me that's not installed. I checked whether it was and I got:
cris#Manaos:~$ dpkg -L python-termcolor
/.
/usr
/usr/share
/usr/share/pyshared
/usr/share/pyshared/termcolor-1.1.0.egg-info
/usr/share/pyshared/termcolor.py
/usr/share/doc
/usr/share/doc/python-termcolor
/usr/share/doc/python-termcolor/README.rst
/usr/share/doc/python-termcolor/copyright
/usr/share/doc/python-termcolor/changelog.Debian.gz
/usr/share/doc/python-termcolor/CHANGES.rst
/usr/lib
/usr/lib/python2.7
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/termcolor-1.1.0.egg-info
/usr/lib/python2.7/dist-packages/termcolor.py
So I understand that the package was correctly installed, but in the v2.7. How do I get it installed in the v3.6?
EDIT: I've read that if a use the pip installer, I could assign in which version of Python I'd like it installed, like using pip3 to install the package in 3.XX. But I tried it, it says that it was correctly installed and when I open Python 3.6 and try to use it, still got the ModuleNotFoundError.
EDIT2: After checking one more time, I discovered that with pip3 I installed the termcolor package in Python 3.5.3, but how can I get it installed in Python 3.6.1?
You need to specify you want the python 3 version.
sudo apt-get install python3-termcolor

Getting "Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?" when installing lxml through pip

I'm getting an error Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed? when trying to install lxml through pip.
c:\users\f\appdata\local\temp\xmlXPathInitqjzysz.c(1) : fatal error C1083: Cannot open include file: 'libxml/xpath.h': No such file or directory
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'C:\\Users\\f\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2
I don't find any libxml2 dev packages to install via pip.
Using Python 2.7 and Python 3.x on x86 in a virtualenv under Windows 10.
Install lxml from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml for your python version. It's a precompiled WHL with required modules/dependencies.
The site lists several packages, when e.g. using Win32 Python 3.11, use lxml‑4.9.0‑cp311‑cp311‑win32.whl.
Download the file, and then install with:
pip install C:\path\to\downloaded\file\lxml‑4.9.0‑cp311‑cp311‑win32.whl
I had this issue and realised that whilst I did have libxml2 installed, I didn't have the necessary development libraries required by the python package. Installing them solved the problem:
sudo apt-get install libxml2-dev libxslt1-dev
sudo pip install lxml
Try to use:
easy_install lxml
That works for me, win10, python 2.7.
On Mac OS X El Capitan I had to run these two commands to fix this error:
xcode-select --install
pip install lxml
Which ended up installing lxml-3.5.0
When you run the xcode-select command you may have to sign a EULA (so have an X-Term handy for the UI if you're doing this on a headless machine).
In case anyone else has the same issue as this on
Centos, try:
yum install python-lxml
Ubuntu
sudo apt-get install -y python-lxml
worked for me.
set STATICBUILD=true && pip install lxml
run this command instead, must have VS C++ compiler installed first
https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/
It works for me with Python 3.5.2 and Windows 7
I tried install a lib that depends lxml and nothing works. I see a message when build was started: "Building without Cython", so after install cython with apt-get install cython, lxml was installed.
I had this issue and realized that while I did have libxml2 installed, I didn't have the necessary development libraries required by the python package.
1) Installing them solved the problem:
The site to download the file: Download
2) After Installing the file save it in a accessible folder
pip install *path to that file*
For some reason it doesn't work in python 3.11, but 3.10 works.
On windows, to install a module with a previous version, use
py -3.10 -m pip install lxml
if you want to install it in a venv, then use
py -3.10 -m venv .venv
.venv/Scripts/pip.exe install lxml
if you've set up the venv, then you can just use
pip install lxml
You also need to run the python program with that version. If you set up a venv, then you don't need to do this.
py -3.10 file.py
It is not strange for me that none of the solutions above came up, but I saw how the igd installation removed the new version and installed the old one, for the solution I downloaded this archive:https://pypi.org/project/igd/#files
and changed the recommended version of the new version: 'lxml==4.3.0' in setup.py
It works!
I got the same error for python 32 bit. After install 64bit, the problem was fixed.
I am using venv.
In my case it was enough to add lxml==4.6.3 to requirements.txt.
One library wanted earlier version and this was causing this error, so when I forced pip to use newest version (currently 4.6.3) installation was successful.

easy_install and pip giving errors when trying to install numpy

I am running Python 2.7.2 on my machine. I am trying to install numpy with easy_install and pip, but none of them are able to do so. So, when I try:
sudo easy_install-2.7 numpy
I get this error:
"The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available."
Moreover, when I try with pip:
sudo pip-2.7 install numpy
I get this error:
RuntimeError: Broken toolchain: cannot link a simple C program
Is there any fix available for this?
I was facing the same error while installing the requirements for my django project. This worked for me.
Upgrade your setuptools version via pip install --upgrade setuptools and run the command for installing the packages again.
you need a compiler and development tools, along with header files for Python.
you didn't mention your OS.
on my system (Ubuntu), I can install python-dev and the toolchain dependencies with:
$ sudo apt-get install python-dev
then I can pip install numpy.

Categories

Resources