Installing lxml, libxml2, libxslt for Python 3.5 on Windows 10
Asked Answered
B

2

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.

Blythe answered 6/11, 2016 at 0:11 Comment(19)
Did you try to download the file named for your python-version? (cp35, not cp36)Lunulate
lxml needs C/C++ libraries libxml2, libxslt - you can't install them using pipMonica
@Lunulate 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.Blythe
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: docs.continuum.io/anaconda/pkg-docsMonica
@Monica 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.Blythe
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 *.hMonica
@Monica what about files available here: 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 PythonBlythe
BTW: see Unofficial Windows Binaries for Python Extension Packages but Anaconda can be the best solution for Windows users.Monica
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.Monica
@Monica 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.Blythe
cp35 in filename means version for Python 3.5. On unofficial page I see lxml for cp34, cp35, cp36.Monica
@Monica 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.Blythe
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.Monica
@Monica Isn't that a wheel for libxml2 python 2.7 on Windows? lfd.uci.edu/~gohlke/pythonlibs/#libxml-python : libxml2_python-2.9.3-cp27-none-win32.whlBlythe
as for lxml i think you use 32bit Python so you need 32bit whl - with win32 in name.Monica
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.Monica
@Monica 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.whlBlythe
Good :) Now you have to learn how to use lxml :) Good luck.Monica
Possible duplicate of Getting "Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?" when installing lxml through pipTeary
M
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

Monica answered 6/11, 2016 at 2:17 Comment(9)
"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?Blackwell
@Blackwell 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.Monica
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.Anaptyxis
How to include it in python (django) application ?..Disruptive
@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.Monica
@SaddamMeshaal libxml2,libxslt precompiled for Windows I found on page zlatkovic.com/projects/libxml/index.html in Getting The Binaries (link download area).Monica
@Monica how can I install it manually, I am starter with python. thanks you in advance.Disruptive
@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.Monica
@Monica I have did that before but still have the same issue: No module named 'libxslt'Disruptive
D
-2

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

Deify answered 24/5, 2020 at 23:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.