Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing lxml, libxml2, libxslt for Python 3.5 on Windows 10

Tags:

python

lxml

I first try to run the basic pip install command for it:

C:\Program Files (x86)\Python35-32>pip install lxml
Collecting lxml
  Using cached lxml-3.6.4.tar.gz
Building wheels for collected packages: lxml
  Running setup.py bdist_wheel for lxml ... error
  Complete output from command "c:\program files (x86)\python35-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\Djidiouf\\AppData\\Local\\Temp\\pip-build-ovqa6ncd\\lxml\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\Djidiouf\AppData\Local\Temp\tmp9hzx5gztpip-wheel- --python-tag cp35:
  Building lxml version 3.6.4.
  Building without Cython.
  ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
  ** make sure the development packages of libxml2 and libxslt are installed **


  C:\Users\Djidiouf\AppData\Local\Temp\xmlXPathInitbqgvj3pt.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:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2

    ----------------------------------------
Command ""c:\program files (x86)\python35-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\Djidiouf\\AppData\\Local\\Temp\\pip-build-ovqa6ncd\\lxml\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Djidiouf\AppData\Local\Temp\pip-kk7fdpzx-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Djidiouf\AppData\Local\Temp\pip-build-ovqa6ncd\lxml\

I tried to install libxml2:

C:\Program Files (x86)\Python35-32>pip install libxml2
Collecting libxml2
  Could not find a version that satisfies the requirement libxml2 (from versions: )
No matching distribution found for libxml2

And I also tried to install libxslt:

C:\Program Files (x86)\Python35-32>pip install libxslt
Collecting libxslt
  Could not find a version that satisfies the requirement libxslt (from versions: )
No matching distribution found for libxslt

I also tried to build lxml from sources ( https://github.com/lxml/lxml ) but it needs the libxml2 dependencies as well.

I tried to install it with wheel as well after downloading the lxml file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml :

C:\Program Files (x86)\Python35-32>pip install C:\Users\Djidiouf\Downloads\lxml-3.6.4-cp35-cp35m-win_amd64.whl
lxml-3.6.4-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.

It seems that this wheel file doesn't support either Windows 10 or Python 3.5.

Any help will be appreciated.

like image 863
Djidiouf Avatar asked Nov 06 '16 00:11

Djidiouf


People also ask

How do I install libxml2 on Windows?

Within c:\tools I have a directory called libxml that contains the stuff I want from these zips. Create a suitable directory to extract the desired content from the zips into. Extract the following files from [the bin subdirectory of] the libxml archive [e.g. libxml2-2.9. 1-win32-x86_64.

How do I get lxml version?

In case you want to use the current in-development version of lxml, you can get it from the github repository at https://github.com/lxml/lxml . Note that this requires Cython to build the sources, see the build instructions on the project home page.


1 Answers

lxml uses libxml2, libxslt (in background) but libxml2, libxslt are not Python modules - it's C/C++ libraries. So you can't install them using pip. You have to download and install them manually.

You can find precompiled lxml for Windows on Unofficial Windows Binaries for Python Extension Packages

  • cp35 in file name means version for Python 3.5.
  • win32 in file name means version for 32bit Python.
  • amd64 in file name means version for 64bit Python.

You probably use 32bit Python because I see 32 and (x86) in your path

C:\program files (x86)\python35-32\python.exe

You should find links to libxml2, libxslt on this page too. This libraries has .dll and .exe files and you can put them in any folder which is in PATH variable. Libraries mostly are installed in C:\Windows or in subfolder.

libxml2, libxslt may have also C/C++ header files *.h which you may need when you compile lxml. (on Linux this files are in separated packages libxml2-dev, libxslt-dev)


BTW: You can use Anaconda distribution (instead of Python.org distribution). It installs the same Python but with some precompiled modules - ie. it installs lxml automatically. Anaconda can be the best solution for Windows users.

List of all modules: https://docs.continuum.io/anaconda/pkg-docs

like image 135
furas Avatar answered Sep 20 '22 12:09

furas