[python] libxml install error using pip

This is my error:

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml
Downloading/unpacking lxml
  Running setup.py egg_info for package lxml
    Building lxml version 2.3.
    Building without Cython.
    ERROR: /bin/sh: xslt-config: not found

    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
Installing collected packages: lxml
  Running setup.py install for lxml
    Building lxml version 2.3.
    Building without Cython.
    ERROR: /bin/sh: xslt-config: not found

    ** make sure the development packages of libxml2 and libxslt are installed **

    Using build configuration of libxslt
    building 'lxml.etree' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
    src/lxml/lxml.etree.c:4: fatal error: Python.h: ?????????
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-jOhgvD-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
    Building lxml version 2.3.

Building without Cython.

ERROR: /bin/sh: xslt-config: not found



** make sure the development packages of libxml2 and libxslt are installed **



Using build configuration of libxslt

running install

running build

running build_py

running build_ext

building 'lxml.etree' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w

src/lxml/lxml.etree.c:4: fatal error: Python.h: ?????????

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-jOhgvD-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log

What can I do?

updated:

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install lxml
Downloading/unpacking lxml
  Running setup.py egg_info for package lxml
    Building lxml version 2.3.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib
Installing collected packages: lxml
  Running setup.py install for lxml
    Building lxml version 2.3.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib
    building 'lxml.etree' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w
    src/lxml/lxml.etree.c:4: fatal error: Python.h: ?????????
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-NJw2ws-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
    Building lxml version 2.3.

Building without Cython.

Using build configuration of libxslt 1.1.26

Building against libxml2/libxslt in the following directory: /usr/lib

running install

running build

running build_py

running build_ext

building 'lxml.etree' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w

src/lxml/lxml.etree.c:4: fatal error: Python.h: ?????????

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/lxml/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-NJw2ws-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Storing complete log in /home/zjm1126/.pip/pip.log

the log:

------------------------------------------------------------
/home/zjm1126/zjm_test/mysite/bin/pip run on Thu Mar  3 17:07:27 2011
Downloading/unpacking mysql-python
  Running setup.py egg_info for package mysql-python
    running egg_info
    creating pip-egg-info/MySQL_python.egg-info
    writing pip-egg-info/MySQL_python.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/MySQL_python.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/MySQL_python.egg-info/dependency_links.txt
    writing pip-egg-info/MySQL_python.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/MySQL_python.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/MySQL_python.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found
    reading manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'ChangeLog'
    warning: no files found matching 'GPL'
    writing manifest file 'pip-egg-info/MySQL_python.egg-info/SOURCES.txt'
Installing collected packages: mysql-python
  Running setup.py install for mysql-python
    Running command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-i686-2.6
    copying _mysql_exceptions.py -> build/lib.linux-i686-2.6
    creating build/lib.linux-i686-2.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb
    creating build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-i686-2.6
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
    In file included from _mysql.c:29:
    pymemcompat.h:10: fatal error: Python.h: ?????????
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6:
    running install

running build

running build_py

creating build

creating build/lib.linux-i686-2.6

copying _mysql_exceptions.py -> build/lib.linux-i686-2.6

creating build/lib.linux-i686-2.6/MySQLdb

copying MySQLdb/__init__.py -> build/lib.linux-i686-2.6/MySQLdb

copying MySQLdb/converters.py -> build/lib.linux-i686-2.6/MySQLdb

copying MySQLdb/connections.py -> build/lib.linux-i686-2.6/MySQLdb

copying MySQLdb/cursors.py -> build/lib.linux-i686-2.6/MySQLdb

copying MySQLdb/release.py -> build/lib.linux-i686-2.6/MySQLdb

copying MySQLdb/times.py -> build/lib.linux-i686-2.6/MySQLdb

creating build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.6/MySQLdb/constants

copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.6/MySQLdb/constants

running build_ext

building '_mysql' extension

creating build/temp.linux-i686-2.6

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-i686-2.6/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX

In file included from _mysql.c:29:

pymemcompat.h:10: fatal error: Python.h: ?????????

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1
Exception information:
Traceback (most recent call last):
  File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/basecommand.py", line 130, in main
    self.run(options, args)
  File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/commands/install.py", line 228, in run
    requirement_set.install(install_options, global_options)
  File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/req.py", line 1043, in install
    requirement.install(install_options, global_options)
  File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/req.py", line 559, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/home/zjm1126/zjm_test/mysite/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg/pip/__init__.py", line 249, in call_subprocess
    % (command_desc, proc.returncode))
InstallationError: Command /home/zjm1126/zjm_test/mysite/bin/python -c "import setuptools;__file__='/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-XuVIux-record/install-record.txt --install-headers /home/zjm1126/zjm_test/mysite/include/site/python2.6 failed with error code 1

This question is related to python lxml pip

The answer is


I am using Ubuntu 12, and this works for me:

sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install python-dev
sudo apt-get install lxml

In case, you are using Ubuntu/Lubuntu 13.04 or Ubuntu 13.10 and having problem with "/usr/bin/ld: cannot find -lz", you may need also install zlib1g-dev package:

sudo apt-get install -y zlib1g-dev

Put it all together:

sudo apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev python3-pip
sudo pip3 install lxml

error: command 'gcc' failed with exit status 1

yum remove audit
yum install gcc
yum install libxslt-devel libxml2-devel

cd lxml-x.x.x
python setup.py build
python setup.py install

This worked for me:

yum install libxslt-devel libxml2-devel

sudo apt install libxslt-dev libxml2-dev

and then try upgrading python setuptools

pip install -U pip setuptools

this should resolve it.


These two packages need to be installed separately and usually can't be installed using pip...Therefore, for FreeBSD:

Download a compressed snapshot of the Ports Collection into /var/db/portsnap:
# portsnap fetch
When running Portsnap for the first time, extract the snapshot into /usr/ports:
# portsnap extract
After the first use of Portsnap has been completed as shown above, /usr/ports can be updated as needed by running:
# portsnap fetch
# portsnap update

Now Install:
cd /usr/ports/textproc/libxml2
make install clean

cd /usr/ports/textproc/libxslt
make install clean

You should be good to go...


On Windows I had the same error on windows when trying to manually install in Python 3.4 after it had been installed on 3.3. I finally was able to solve it by installing the wheel and running pip from the Python34 directory.

1) download wheel from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

2) cd Python34\Scripts

3) pip.exe C:\Users\Home\Downloads\lxml- ......... .whl


I know I am late to the show,

But this will help if nothing else works out

mkdir ~/tmp
export TMPDIR=~/tmp
STATIC_DEPS=true easy_install-2.7 lxml

Setting TMPDIR will ensure that the build can run everything that it needs to run, and setting STATIC_DEPS will tell it to pull in its own libxml2 and libxslt2, instead of using the old versions installed on the server.


This works for me, 12.04, python2.7.6

sudo apt-get install libxml2 libxml2-dev libxslt1-dev
sudo pip install lxml

I work on a Windows machine. And here are some pointers for successful installation of lxml (with python 2.6 and later).

Have the following installed:

  1. MingGW.
  2. libxml2 version 2.7.0 or later.
  3. libxslt version 1.1.23 or later.

All are not available at a pip install.

libxml2's windows binary is found here.

libxslt is found here.

After you are done with the above two,

do : pip install lxml.

Another workaround is using the stable releases from PyPI or the unofficial Windows binaries by Christoph Gohlke (found here).


just install requirements:

sudo apt-get install libxml2-dev libxslt-dev python-dev

Now, you can install it with pip package management tool:

pip install lxml

For python3 users:

sudo apt-get install libxml2-dev libxslt-dev python3-dev

pip3 install lxml

I solved this issue by increasing my server ram.

I was running only 512 MB and when I upgraded to 1 GB I had no problem.

I also installed every package manually prior to this in an attempt to fix the problem, but I'm not sure whether this is a necessary step.


All the answers above assume the user has access to a privileged/root account to install the required libraries. To install it locally you will need to do the following steps. Only showed the overview since the steps can get a little involved depending on the dependencies that you might be missing

1.Download and Compile libxml2-2.9.1 & libxslt-1.1.28(versions might change)

2.Configure each install path for both libxml and libxslt to be some local directory using configure. Ex. ./configure --prefix=/home_dir/dependencies/libxslt_path

3.Run make then make install

4.Download and compile lxml from source


pymemcompat.h:10: fatal error: Python.h: ?????????

Boy you should post your error log with LANG=C or people can't get the real cause from your log. The log above says: No such file or directory.

That means you should install the develop package of Python. That's usually "python-dev" on Debian flavored distro, and "python-devel" on RHEL flavored distro.


I am using Ubuntu 14.04 and this solves the issue for me

sudo apt-get build-dep python3-lxml
sudo apt-get install libxml2-dev libxslt-dev python-dev

On osx 10.10.5 and in a virtualenv, maybe you can resolve that problem like below:

sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include pip install -r lxml

The below file worked for me on windows https://pypi.python.org/pypi/lxml/3.3.3#downloads


If you have installed the libxml2 and libxslt, maybe you need to create a symbolic link between libxml2 and libxslt path to python2.6 include path. Also you can try to add INCLUDE environment argument. Because the gcc command only search this path: -I/usr/include/python2.6.


No you are missing the Python header files. This mostly happens on Linux when you are using the system Python (there are reasons not to do that, but that's a different question).

You probably need to install some package, and it's probably called python-dev or python-devel.

 sudo yum install python-devel

or

 sudo aptitude install python-dev

Or somesuch.


** make sure the development packages of libxml2 and libxslt are installed **

From the lxml documentation, assuming you are running a Debian-based distribution :

sudo apt-get install libxml2-dev libxslt-dev python-dev

For Debian based systems, it should be enough to install the known build dependencies of python-lxml or python3-lxml, e.g.

sudo apt-get build-dep python3-lxml

Using Windows 7 with Cygwin, I came across:

Compile failed: command 'gcc' failed with exit status 1
cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitZsgdMQ.c -o tmp/xmlXPathInitZsgdMQ.o
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'gcc' failed with exit status 1

I fixed it by installing mingw64-x86_64-libxslt


The only thing helped for me was

sudo apt-get install python3.5-dev

I was having this issue with a pip install of lxml. My CentOS instance was using python 2.6 which was throwing this error.

To get around this I did the following to run with Python 2.7:

  1. Run: sudo yum install python-devel
  2. Run sudo yum install libxslt-devel libxml2-devel
  3. Use Python 2.7 to run your command by using /usr/bin/python2.7 YOUR_PYTHON_COMMAND (For me it was /usr/bin/python2.7 -m pip install lxml)

Using cygwin 64 with Windows 8.

I have got...

pip install lxml (...)

gcc -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python3/python3-3.2.5-4.x86_64/build=/usr/src/debug/python3-3.2.5-4 -fdebug-prefix-map=/usr/src/ports/python3/python3-3.2.5-4.x86_64/src/Python-3.2.5=/usr/src/debug/python3-3.2.5-4 -I/usr/include/libxml2 -I/tmp/pip-build-b8ybku/lxml/src/lxml/includes -I/usr/include/python3.2m -c src/lxml/lxml.etree.c -o build/temp.cygwin-1.7.34-x86_64-3.2/src/lxml/lxml.etree.o -w

src/lxml/lxml.etree.c:8:22: fatal error: pyconfig.h: No such file or directory

compilation terminated.

/usr/lib/python3.2/distutils/dist.py:257: UserWarning: Unknown distribution option: 'bugtrack_url'

  warnings.warn(msg)

error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/usr/bin/python3.2m -c "import setuptools, tokenize;__file__='/tmp/pip-build-b8ybku/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-u3vwj8-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-b8ybku/lxml

I have tried everything until I realized a new cygwin toolchain has messed up python logic. cygwin install a compiler called "realgcc" that is not a real gcc.

Solution

Install gcc. Ex:

 apt-cyg install gcc-g++

I got the same error on my Linux machine.If you go to their website that's in their documentation as well.So if you get this kind of error in Linux machine, please try out these commands,

# apt install libxml2-dev libxslt-dev python-dev

# pip install lxml==3.4.4


For Windows:

pip install --upgrade pip wheel
pip install bzt
pip install lxml

STATIC_DEPS=true easy_install lxml

Installing a lxml binary would do the trick. Check this


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to lxml

pip is not able to install packages correctly: Permission denied error bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? Flask example with POST SyntaxError of Non-ASCII character How to install lxml on Ubuntu builtins.TypeError: must be str, not bytes libxml install error using pip Installing lxml module in python How to select following sibling/xml tag using xpath

Examples related to pip

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main'