Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems installing lxml in Ubuntu

Getting the following errors when I do: pip install lxml

You are using pip version 6.0.8, however version 7.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.                                                                                          
Collecting lxml
  Using cached lxml-3.4.4.tar.gz
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.4.4.
    Building without Cython.
    ERROR: /bin/sh: 1: 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
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.4.4.
    Building without Cython.
    ERROR: /bin/sh: 1: xslt-config: not found
    ** make sure the development packages of libxml2 and libxslt are installed **
    Using build configuration of libxslt
    building 'lxml.etree' extension
    i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip-build-RLyvkw/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w
    In file included from src/lxml/lxml.etree.c:239:0:
    /tmp/pip-build-RLyvkw/lxml/src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory
     #include "libxml/xmlversion.h"
                                   ^
    compilation terminated.
    error: command 'i686-linux-gnu-gcc' failed with exit status 1
    Complete output from command /home/apurva/.virtualenvs/universallogin/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-RLyvkw/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-9WRQzF-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/apurva/.virtualenvs/universallogin/include/site/python2.7:
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
    
      warnings.warn(msg)
    
    Building lxml version 3.4.4.
    
    Building without Cython.
    
    ERROR: /bin/sh: 1: 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
    
    creating build
    
    creating build/lib.linux-i686-2.7
    
    creating build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/pyclasslookup.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/doctestcompare.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/sax.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/_elementpath.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/__init__.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/builder.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/ElementInclude.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/cssselect.py -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/usedoctest.py -> build/lib.linux-i686-2.7/lxml
    
    creating build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/__init__.py -> build/lib.linux-i686-2.7/lxml/includes
    
    creating build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/soupparser.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/html5parser.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/_setmixin.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/diff.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/formfill.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/_diffcommand.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/ElementSoup.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/__init__.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/builder.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/defs.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/_html5builder.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/usedoctest.py -> build/lib.linux-i686-2.7/lxml/html
    
    copying src/lxml/html/clean.py -> build/lib.linux-i686-2.7/lxml/html
    
    creating build/lib.linux-i686-2.7/lxml/isoschematron
    
    copying src/lxml/isoschematron/__init__.py -> build/lib.linux-i686-2.7/lxml/isoschematron
    
    copying src/lxml/lxml.etree.h -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/lxml.etree_api.h -> build/lib.linux-i686-2.7/lxml
    
    copying src/lxml/includes/htmlparser.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/xinclude.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/c14n.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/xpath.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/etreepublic.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/schematron.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/xslt.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/tree.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/config.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/xmlschema.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/xmlerror.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/xmlparser.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/dtdvalid.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/uri.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/relaxng.pxd -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/etree_defs.h -> build/lib.linux-i686-2.7/lxml/includes
    
    copying src/lxml/includes/lxml-version.h -> build/lib.linux-i686-2.7/lxml/includes
    
    creating build/lib.linux-i686-2.7/lxml/isoschematron/resources
    
    creating build/lib.linux-i686-2.7/lxml/isoschematron/resources/rng
    
    copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/rng
    
    creating build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl
    
    copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl
    
    copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl
    
    creating build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.linux-i686-2.7/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    
    running build_ext
    
    building 'lxml.etree' extension
    
    creating build/temp.linux-i686-2.7
    
    creating build/temp.linux-i686-2.7/src
    
    creating build/temp.linux-i686-2.7/src/lxml
    
    i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/pip-build-RLyvkw/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w
    
    In file included from src/lxml/lxml.etree.c:239:0:
    
    /tmp/pip-build-RLyvkw/lxml/src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory
    
     #include "libxml/xmlversion.h"
    
                                   ^
    
    compilation terminated.
    
    error: command 'i686-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
    Command "/home/apurva/.virtualenvs/universallogin/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-RLyvkw/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-9WRQzF-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/apurva/.virtualenvs/universallogin/include/site/python2.7" failed with error code 1 in /tmp/pip-build-RLyvkw/lxml

I've already tried this: sudo apt-get install zlib1g-dev before "pip install" reading this answer: Not able to install lxml verison 3.3.5 in ubuntu

but did not help. Also, tried installing python-dev, python3-dev, lib-eventdev did not help either.

Also, tried doing this: STATIC_DEPS=true pip install lxml reading this: http://lxml.de/installation.html

Did not help either! Will be very grateful if you could suggest something Thanks in advance.

like image 827
Apurva Jha Avatar asked Jul 16 '15 19:07

Apurva Jha


2 Answers

The output states ** make sure the development packages of libxml2 and libxslt are installed **. Have you done that?

sudo apt-get install libxml2-dev libxslt-dev

Also, is there a particular reason you're install using pip instead of installing the python-lxml package that comes with Ubuntu? Installing your distribution's package should be preferred unless you have a reason to do otherwise.

like image 86
jamessan Avatar answered Oct 09 '22 11:10

jamessan


if you don't need a specific version from PyPI, you can always use the version packaged for Ubuntu.

$ sudo apt-get install python-lxml

... and then allow system site packages in your virtualenv.


update:

for clarification... pip installs python packages from PyPI by default. However, many python packages are also packaged for Ubuntu and stored in the Ubuntu archives, You can install them via your system package manager (apt-get) instead of using pip. This can be helpful as the Ubuntu packages are compiled already, and will pull in any dependencies they need.

By default, virtualenv creates an isolated python enviornment, so you don't have access to system packages (that you installed using apt-get). However, you can allow system site packages in your virtualenv.

for example, let's install lxml from it's system package, create a virtualenv named "ENV" that allows access to system packages, and then import lxml to verify it works:

$ sudo apt-get install python-lxml
$ virtualenv --system-site-packages ENV
$ source ENV/bin/activate
(ENV)$ python -c "import xml"
like image 24
Corey Goldberg Avatar answered Oct 09 '22 11:10

Corey Goldberg