12

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.

Djidiouf
  • 786
  • 1
  • 10
  • 23
  • Did you try to download the file named for your python-version? (cp3**5**, not cp3**6**) – MatsLindh Nov 06 '16 at 00:13
  • `lxml` needs C/C++ libraries `libxml2`, `libxslt` - you can't install them using `pip` – furas Nov 06 '16 at 00:17
  • @MatsLindh sorry I tried the cp36 and previously the cp35 but only copy paste the later output, I edited my question. so Yes I tried and got the exact same result. – Djidiouf Nov 06 '16 at 00:19
  • Maybe use `Anaconda` distribution (instead of `Python.org` distribution). It installs the same Python with precompiled modules - ie. it installs `lxml` as default - List of modules: https://docs.continuum.io/anaconda/pkg-docs – furas Nov 06 '16 at 00:20
  • @furas thank you for your comment. However, as you can see in my question, after my first initial try to install lxml, I tried to install libxml2 and libxslt but it also failed, and then I try to install an already compiled wheel of lxml. – Djidiouf Nov 06 '16 at 00:21
  • as I sad before `libxml2` and `libxslt` are not Python modules but C/C++ libraries - you can't install it with `pip`. You have to download it and install like any other program in Windows. If you want to compile `lxml` then you may need `libxml2-dev` and `libxslt-dev` with C/C++ headers files `*.h` – furas Nov 06 '16 at 00:22
  • @furas what about files available here: ftp://xmlsoft.org/libxml2/win32/ can I download those (it contains the headers in it), but I don't know where to put those libraries in order to have them being checked by Python – Djidiouf Nov 06 '16 at 00:26
  • BTW: see [Unofficial Windows Binaries for Python Extension Packages](http://www.lfd.uci.edu/~gohlke/pythonlibs/) but `Anaconda` can be the best solution for Windows users. – furas Nov 06 '16 at 00:26
  • I don't use Windows any more but as I remember you can put .dll and .exe in `C:\\Windows` or any folder which is in `PATH` variable. Python should find it. – furas Nov 06 '16 at 00:28
  • @furas I went on the unofficial windows binaries page, unfortunately, both the lxml and the libxml2 (this one doesn't have a version available for python 3.x) .whl aren't supported. – Djidiouf Nov 06 '16 at 00:31
  • `cp35` in filename means version for Python 3.5. On unofficial page I see `lxml` for cp34, cp35, cp36. – furas Nov 06 '16 at 00:35
  • @furas Yes and I tried this cp35 version for lxml. See at the end of my question: "lxml-3.6.4-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform." For the libxml2 wheel, it doesn't exist for 3.x version. – Djidiouf Nov 06 '16 at 00:44
  • I sad two times `libxml2` is NOT python module - there is NO wheel for `libxml2`. It is C/C++ library - with files .dll and .exe - and you have to download and install manually or as any other program/library in Windows. – furas Nov 06 '16 at 00:46
  • @furas Isn't that a wheel for libxml2 python 2.7 on Windows? http://www.lfd.uci.edu/~gohlke/pythonlibs/#libxml-python : libxml2_python-2.9.3-cp27-none-win32.whl – Djidiouf Nov 06 '16 at 00:48
  • 1
    as for `lxml` i think you use 32bit Python so you need 32bit `whl` - with `win32` in name. – furas Nov 06 '16 at 00:50
  • `libxml2_python` can be wrapper for C/C++ libxml2. Simmilar `lxml` is wrapper for C/C++ libxml2. `lxml` doesn't need `libxml2_python` but C/C++ libxml2. – furas Nov 06 '16 at 00:53
  • @furas ok that makes sense now. As you spotted it at the end, the wheel I was trying to access was for x64 and my python is 32. I was thinking it was dependent of my Windows architecture. Eventually, lxml is now correctly installed using lxml-3.6.4-cp35-cp35m-win32.whl – Djidiouf Nov 06 '16 at 00:56
  • 1
    Good :) Now you have to learn how to use `lxml` :) Good luck. – furas Nov 06 '16 at 01:01
  • Possible duplicate of [Getting "Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?" when installing lxml through pip](https://stackoverflow.com/questions/33785755/getting-could-not-find-function-xmlcheckversion-in-library-libxml2-is-libxml2) – Stevoisiak Feb 13 '18 at 15:39

2 Answers2

10

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

furas
  • 134,197
  • 12
  • 106
  • 148
  • "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." This is the part I don't understand. How do we actually install the wheels if we can't use pip because of the 'wheel not supported on this platform'? Simply putting the wheels in the Windows folder won't do anything? – Calydon Oct 17 '19 at 01:30
  • 1
    @Calydon I don't talk about python's modules but about libraries created with C/C++ which you download as .zip file. Python's module `lxml` needs them to run correctly. – furas Oct 17 '19 at 01:35
  • 2
    As this is one of the more recent posts (or up-to-date) on this topic. I ran into these issues with `lxml==4.5.1` and windows 10, python 3.9. I eventually installed Visual Studio with C++ support and `pip install setuptools` and switched to `lxml==4-6-2` and to much surprise it worked. No pre-compiled binaries required. – Martin Mar 20 '21 at 21:58
  • How to include it in python (django) application ?.. – Saddam Meshaal Nov 03 '22 at 19:46
  • 1
    @SaddamMeshaal `libxml2`, `libxslt` are C/C++ libraries and they are not part of Python - you have to install them manually on Windows (on Linux Ubuntu/Debian you could use `apt install libxml2 libxslt`). And `lxml` is Python module and you install it as any other module - using `pip`. – furas Nov 03 '22 at 22:21
  • 1
    @SaddamMeshaal `libxml2`,`libxslt` precompiled for Windows I found on page https://www.zlatkovic.com/projects/libxml/index.html in `Getting The Binaries` (link [download area](https://www.zlatkovic.com/pub/libxml/)). – furas Nov 03 '22 at 22:35
  • @furas how can I install it manually, I am starter with python. thanks you in advance. – Saddam Meshaal Nov 04 '22 at 11:36
  • 1
    @SaddamMeshaal you have to download `.zip` file, uncompress and put file `.dll` in one of folder which you have in variable `PATH`. I don't use Windows but probably folder `C:\Windows` should be in this variable. – furas Nov 04 '22 at 21:50
  • @furas I have did that before but still have the same issue: No module named 'libxslt' – Saddam Meshaal Nov 06 '22 at 15:27
-2

Also, check your pip --version. I had v19.0 and Gohlke .whl binaries would not install. Upgrade to 19.2 or greater.

Matt
  • 1