How to install lxml on Windows
Question:
I’m trying to install lmxl
on my Windows 8.1 laptop with Python 3.4 and failing miserably.
First off, I tried the simple and obvious solution: pip install lxml
. However, this didn’t work. Here’s what it said:
Downloading/unpacking lxml
Running setup.py (path:C:UsersCARTE_~1AppDataLocalTemppip_build_carte_000lxmlsetup.py) egg_info for package lxml
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
Running setup.py install for lxml
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
building 'lxml.etree' extension
C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
error: Unable to find vcvarsall.bat
Complete output from command C:Python34python.exe -c "import setuptools, tokenize;__file__='C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record C:UsersCARTE_~1AppDataLocalTemppip-l8vvrv9g-recordinstall-record.txt --single-version-externally-managed --compile:
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** 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 buildlib.win32-3.4
creating buildlib.win32-3.4lxml
copying srclxmlbuilder.py -> buildlib.win32-3.4lxml
copying srclxmlcssselect.py -> buildlib.win32-3.4lxml
copying srclxmldoctestcompare.py -> buildlib.win32-3.4lxml
copying srclxmlElementInclude.py -> buildlib.win32-3.4lxml
copying srclxmlpyclasslookup.py -> buildlib.win32-3.4lxml
copying srclxmlsax.py -> buildlib.win32-3.4lxml
copying srclxmlusedoctest.py -> buildlib.win32-3.4lxml
copying srclxml_elementpath.py -> buildlib.win32-3.4lxml
copying srclxml__init__.py -> buildlib.win32-3.4lxml
creating buildlib.win32-3.4lxmlincludes
copying srclxmlincludes__init__.py -> buildlib.win32-3.4lxmlincludes
creating buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlbuilder.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlclean.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmldefs.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmldiff.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlElementSoup.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlformfill.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlhtml5parser.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlsoupparser.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlusedoctest.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml_diffcommand.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml_html5builder.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml_setmixin.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml__init__.py -> buildlib.win32-3.4lxmlhtml
creating buildlib.win32-3.4lxmlisoschematron
copying srclxmlisoschematron__init__.py -> buildlib.win32-3.4lxmlisoschematron
copying srclxmllxml.etree.h -> buildlib.win32-3.4lxml
copying srclxmllxml.etree_api.h -> buildlib.win32-3.4lxml
copying srclxmlincludesc14n.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesconfig.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesdtdvalid.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesetreepublic.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludeshtmlparser.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesrelaxng.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesschematron.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludestree.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesuri.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxinclude.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxmlerror.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxmlparser.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxmlschema.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxpath.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxslt.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesetree_defs.h -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludeslxml-version.h -> buildlib.win32-3.4lxmlincludes
creating buildlib.win32-3.4lxmlisoschematronresources
creating buildlib.win32-3.4lxmlisoschematronresourcesrng
copying srclxmlisoschematronresourcesrngiso-schematron.rng -> buildlib.win32-3.4lxmlisoschematronresourcesrng
creating buildlib.win32-3.4lxmlisoschematronresourcesxsl
copying srclxmlisoschematronresourcesxslRNG2Schtrn.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsl
copying srclxmlisoschematronresourcesxslXSD2Schtrn.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsl
creating buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_abstract_expand.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_dsdl_include.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_schematron_message.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_schematron_skeleton_for_xslt1.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_svrl_for_xslt1.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1readme.txt -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
running build_ext
building 'lxml.etree' extension
C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
error: Unable to find vcvarsall.bat
----------------------------------------
Cleaning up...
Command C:Python34python.exe -c "import setuptools, tokenize;__file__='C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record C:UsersCARTE_~1AppDataLocalTemppip-l8vvrv9g-recordinstall-record.txt --single-version-externally-managed --compile failed with error code 1 in C:UsersCARTE_~1AppDataLocalTemppip_build_carte_000lxml
Storing debug log for failure in C:Userscarte_000pippip.log
So then I looked on this great and helpful thing called The Internet and a lot of people have the same error of needing libxml2
and libxlst
. They recommend a guy called Christoph Gohlke’s page where he provides some sort of binary thingy for a bunch of packages. You can find it here (quicklink to the lxml part).
So after I gave up on trying to find libxml2 and libxslt for pip, I decided to go there, and found an absolute ton of downloads. I know I need a 64-bit one, but I have no idea which “cp
” I need.
So an answer either giving me a solution on the pip
method or the Gohlke index method would be great.
Answers:
First, following the comments, I downloaded the lxml-3.4.2-cp34-none-win_amd64.whl
file and tried to open it with a pip install
, but it just told me it wasn’t a valid wheel file on my system or something.
Then, I downloaded the win_32
file and it worked! Maybe it’s because I have an Intel processor and AMD64 is, unsurprisingly, only for AMD processors.
Or you can also go to Christoph’s Gohlke’s Python page and then download the right lxml file. (Generally since I use python 3.4 and I have a windows, I download the lxml-3.4.4-cp34-none-win32.whl)
Go to the folder it is in. Click in the background (so nothing is selected), then leftshift + rightclick at the same time and click on open command window. Then type
C:/Python34/Scripts/pip install "NAME OF THE FILE YOU JUST DOWNLOADED.whl"
In this case it would be C:/Python34/Scripts/pip install "lxml-3.4.4-cp34-none-win32.whl"
Now hit enter. This worked well for me, and after you type the quote you can also press tab and it should fill the right one for you.
These instructions are for Windows7 or Windows8 with Python3.4.
However, they should work for various versions as the releases of python and other respective prerequisites change/evolve:
- Install Python3.4:
- Download the last release of Python3.4 from the downloads page HERE
- Direct link for Win32 MSI installer -> HERE
- Simply run the MSI to install python. It will register itself in the registry, and appear in Add/REmove Programs.
- NOTE: my instructions that follow assume that you choose to install python to the default path of
C:python34
when asked during the Python Installation Wizard
- Add the
C:python33
and C:python34scripts
folders to the system path by adding those directories to the PATH
environment variable from the Control Panel > System > Advanced System Settings link (Advanced Tab) > Environmental Variables (Button).
- Install OpenSSL:
- Download Win32 OpenSSL page from HERE for your version of Windows and PC architecture
- Download Visual C++ 2008 redistributables for your version of Windows and PC architecture
- Download OpenSSL for your version of Windows and architecture (the regular version, not the light one)
- Add the
c:openssl-win32bin
(or similar) directory to your PATH
, the same way you added C:python34
and C:python34scripts
above.
- Install Setuptools (
get-pip.py
should install Setuptools for you), but, just in case…
- Download
ez_setup.py
HERE and save it in C:python34scripts
- Run
C:python34scripts> python ez_setup.py
- Install PIP
- Download
get-pip.py
from HERE and save it in C:python34scripts
- Run
C:python34scripts> python get-pip.py
- Install LXML
- Download
LXML 3.4.4
from HERE for your version of Windows and PC architecture
- Run the EXE file
I also meet this problem recently. pip can’t not work on .whl file. Instead of fixing this, i install it through .exe file. you can download it from here.Please choose the right version of your python. Hope this can help you.
Looks like today in 2018, lxml
can be installed from PyPI:
C:UsersAdministrator>"c:Program FilesPython37python.exe" -m pip install -U pip wheel setuptools
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 3.3MB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/5a/9b/6aebe9e2636d35d1a93772fa644c828303e1d5d124e8a88f156f42ac4b87/wheel-0.32.2-py2.py3-none-any.whl
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl (569kB)
100% |████████████████████████████████| 573kB 2.9MB/s
Installing collected packages: pip, wheel, setuptools
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
The script wheel.exe is installed in 'c:Program FilesPython37Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Found existing installation: setuptools 39.0.1
Uninstalling setuptools-39.0.1:
Successfully uninstalled setuptools-39.0.1
Successfully installed pip-18.1 setuptools-40.4.3 wheel-0.32.2
C:UsersAdministrator>pip install lxml
Collecting lxml
Downloading https://files.pythonhosted.org/packages/d7/9d/1aa28aa9d293a816baec6c37328d6465b722b2ff3f4d1e93ed56e87813ee/lxml-4.2.5-cp37-cp37m-win_amd64.whl (3.6MB)
100% |████████████████████████████████| 3.6MB 1.6MB/s
Installing collected packages: lxml
Successfully installed lxml-4.2.5
C:UsersAdministrator>python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from io import BytesIO
>>> some_file_or_file_like_object = BytesIO(b"<root>data</root>")
>>> from lxml import etree
>>> tree = etree.parse(some_file_or_file_like_object)
>>> etree.tostring(tree)
b'<root>data</root>'
I had this issue with a requirements file that listed lxml==4.2.1. However, I was able to fix the problem by updating this to lxml==4.2.5.
From the distributer’s website, the correct command is:
pip install lxml==3.4.4
Of course, update version number to match the latest version.
Reference: https://pypi.org/project/lxml/3.4.4/
Go to this page – https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
Download the libxml which is compatible with you machine.
For example, in my case, I have 64-bit intel processor with python 3.10 installed.
so , I have downloaded lxml‑4.6.3‑cp310‑cp310‑win_amd64.whl .
then run –
pip install "download_path/lxml-4.6.3-cp310-cp310-win_amd64.whl"
I’m trying to install lmxl
on my Windows 8.1 laptop with Python 3.4 and failing miserably.
First off, I tried the simple and obvious solution: pip install lxml
. However, this didn’t work. Here’s what it said:
Downloading/unpacking lxml
Running setup.py (path:C:UsersCARTE_~1AppDataLocalTemppip_build_carte_000lxmlsetup.py) egg_info for package lxml
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
Running setup.py install for lxml
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
building 'lxml.etree' extension
C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
error: Unable to find vcvarsall.bat
Complete output from command C:Python34python.exe -c "import setuptools, tokenize;__file__='C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record C:UsersCARTE_~1AppDataLocalTemppip-l8vvrv9g-recordinstall-record.txt --single-version-externally-managed --compile:
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** 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 buildlib.win32-3.4
creating buildlib.win32-3.4lxml
copying srclxmlbuilder.py -> buildlib.win32-3.4lxml
copying srclxmlcssselect.py -> buildlib.win32-3.4lxml
copying srclxmldoctestcompare.py -> buildlib.win32-3.4lxml
copying srclxmlElementInclude.py -> buildlib.win32-3.4lxml
copying srclxmlpyclasslookup.py -> buildlib.win32-3.4lxml
copying srclxmlsax.py -> buildlib.win32-3.4lxml
copying srclxmlusedoctest.py -> buildlib.win32-3.4lxml
copying srclxml_elementpath.py -> buildlib.win32-3.4lxml
copying srclxml__init__.py -> buildlib.win32-3.4lxml
creating buildlib.win32-3.4lxmlincludes
copying srclxmlincludes__init__.py -> buildlib.win32-3.4lxmlincludes
creating buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlbuilder.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlclean.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmldefs.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmldiff.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlElementSoup.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlformfill.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlhtml5parser.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlsoupparser.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtmlusedoctest.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml_diffcommand.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml_html5builder.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml_setmixin.py -> buildlib.win32-3.4lxmlhtml
copying srclxmlhtml__init__.py -> buildlib.win32-3.4lxmlhtml
creating buildlib.win32-3.4lxmlisoschematron
copying srclxmlisoschematron__init__.py -> buildlib.win32-3.4lxmlisoschematron
copying srclxmllxml.etree.h -> buildlib.win32-3.4lxml
copying srclxmllxml.etree_api.h -> buildlib.win32-3.4lxml
copying srclxmlincludesc14n.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesconfig.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesdtdvalid.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesetreepublic.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludeshtmlparser.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesrelaxng.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesschematron.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludestree.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesuri.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxinclude.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxmlerror.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxmlparser.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxmlschema.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxpath.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesxslt.pxd -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludesetree_defs.h -> buildlib.win32-3.4lxmlincludes
copying srclxmlincludeslxml-version.h -> buildlib.win32-3.4lxmlincludes
creating buildlib.win32-3.4lxmlisoschematronresources
creating buildlib.win32-3.4lxmlisoschematronresourcesrng
copying srclxmlisoschematronresourcesrngiso-schematron.rng -> buildlib.win32-3.4lxmlisoschematronresourcesrng
creating buildlib.win32-3.4lxmlisoschematronresourcesxsl
copying srclxmlisoschematronresourcesxslRNG2Schtrn.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsl
copying srclxmlisoschematronresourcesxslXSD2Schtrn.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsl
creating buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_abstract_expand.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_dsdl_include.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_schematron_message.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_schematron_skeleton_for_xslt1.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1iso_svrl_for_xslt1.xsl -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
copying srclxmlisoschematronresourcesxsliso-schematron-xslt1readme.txt -> buildlib.win32-3.4lxmlisoschematronresourcesxsliso-schematron-xslt1
running build_ext
building 'lxml.etree' extension
C:Python34libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
error: Unable to find vcvarsall.bat
----------------------------------------
Cleaning up...
Command C:Python34python.exe -c "import setuptools, tokenize;__file__='C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record C:UsersCARTE_~1AppDataLocalTemppip-l8vvrv9g-recordinstall-record.txt --single-version-externally-managed --compile failed with error code 1 in C:UsersCARTE_~1AppDataLocalTemppip_build_carte_000lxml
Storing debug log for failure in C:Userscarte_000pippip.log
So then I looked on this great and helpful thing called The Internet and a lot of people have the same error of needing libxml2
and libxlst
. They recommend a guy called Christoph Gohlke’s page where he provides some sort of binary thingy for a bunch of packages. You can find it here (quicklink to the lxml part).
So after I gave up on trying to find libxml2 and libxslt for pip, I decided to go there, and found an absolute ton of downloads. I know I need a 64-bit one, but I have no idea which “cp
” I need.
So an answer either giving me a solution on the pip
method or the Gohlke index method would be great.
First, following the comments, I downloaded the lxml-3.4.2-cp34-none-win_amd64.whl
file and tried to open it with a pip install
, but it just told me it wasn’t a valid wheel file on my system or something.
Then, I downloaded the win_32
file and it worked! Maybe it’s because I have an Intel processor and AMD64 is, unsurprisingly, only for AMD processors.
Or you can also go to Christoph’s Gohlke’s Python page and then download the right lxml file. (Generally since I use python 3.4 and I have a windows, I download the lxml-3.4.4-cp34-none-win32.whl)
Go to the folder it is in. Click in the background (so nothing is selected), then leftshift + rightclick at the same time and click on open command window. Then type
C:/Python34/Scripts/pip install "NAME OF THE FILE YOU JUST DOWNLOADED.whl"
In this case it would be C:/Python34/Scripts/pip install "lxml-3.4.4-cp34-none-win32.whl"
Now hit enter. This worked well for me, and after you type the quote you can also press tab and it should fill the right one for you.
These instructions are for Windows7 or Windows8 with Python3.4.
However, they should work for various versions as the releases of python and other respective prerequisites change/evolve:
- Install Python3.4:
- Download the last release of Python3.4 from the downloads page HERE
- Direct link for Win32 MSI installer -> HERE
- Simply run the MSI to install python. It will register itself in the registry, and appear in Add/REmove Programs.
- NOTE: my instructions that follow assume that you choose to install python to the default path of
C:python34
when asked during the Python Installation Wizard
- Download the last release of Python3.4 from the downloads page HERE
- Add the
C:python33
andC:python34scripts
folders to the system path by adding those directories to thePATH
environment variable from the Control Panel > System > Advanced System Settings link (Advanced Tab) > Environmental Variables (Button). - Install OpenSSL:
- Download Win32 OpenSSL page from HERE for your version of Windows and PC architecture
- Download Visual C++ 2008 redistributables for your version of Windows and PC architecture
- Download OpenSSL for your version of Windows and architecture (the regular version, not the light one)
- Add the
c:openssl-win32bin
(or similar) directory to yourPATH
, the same way you addedC:python34
andC:python34scripts
above.
- Install Setuptools (
get-pip.py
should install Setuptools for you), but, just in case…- Download
ez_setup.py
HERE and save it inC:python34scripts
- Run
C:python34scripts> python ez_setup.py
- Download
- Install PIP
- Download
get-pip.py
from HERE and save it inC:python34scripts
- Run
C:python34scripts> python get-pip.py
- Download
- Install LXML
- Download
LXML 3.4.4
from HERE for your version of Windows and PC architecture - Run the EXE file
- Download
I also meet this problem recently. pip can’t not work on .whl file. Instead of fixing this, i install it through .exe file. you can download it from here.Please choose the right version of your python. Hope this can help you.
Looks like today in 2018, lxml
can be installed from PyPI:
C:UsersAdministrator>"c:Program FilesPython37python.exe" -m pip install -U pip wheel setuptools
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 3.3MB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/5a/9b/6aebe9e2636d35d1a93772fa644c828303e1d5d124e8a88f156f42ac4b87/wheel-0.32.2-py2.py3-none-any.whl
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl (569kB)
100% |████████████████████████████████| 573kB 2.9MB/s
Installing collected packages: pip, wheel, setuptools
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
The script wheel.exe is installed in 'c:Program FilesPython37Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Found existing installation: setuptools 39.0.1
Uninstalling setuptools-39.0.1:
Successfully uninstalled setuptools-39.0.1
Successfully installed pip-18.1 setuptools-40.4.3 wheel-0.32.2
C:UsersAdministrator>pip install lxml
Collecting lxml
Downloading https://files.pythonhosted.org/packages/d7/9d/1aa28aa9d293a816baec6c37328d6465b722b2ff3f4d1e93ed56e87813ee/lxml-4.2.5-cp37-cp37m-win_amd64.whl (3.6MB)
100% |████████████████████████████████| 3.6MB 1.6MB/s
Installing collected packages: lxml
Successfully installed lxml-4.2.5
C:UsersAdministrator>python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from io import BytesIO
>>> some_file_or_file_like_object = BytesIO(b"<root>data</root>")
>>> from lxml import etree
>>> tree = etree.parse(some_file_or_file_like_object)
>>> etree.tostring(tree)
b'<root>data</root>'
I had this issue with a requirements file that listed lxml==4.2.1. However, I was able to fix the problem by updating this to lxml==4.2.5.
From the distributer’s website, the correct command is:
pip install lxml==3.4.4
Of course, update version number to match the latest version.
Reference: https://pypi.org/project/lxml/3.4.4/
Go to this page – https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
Download the libxml which is compatible with you machine.
For example, in my case, I have 64-bit intel processor with python 3.10 installed.
so , I have downloaded lxml‑4.6.3‑cp310‑cp310‑win_amd64.whl .
then run –
pip install "download_path/lxml-4.6.3-cp310-cp310-win_amd64.whl"