How to install lxml on Windows

Looks like today in 2018, lxml can be installed from PyPI:

C:\Users\Administrator>"c:\Program Files\Python37\python.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 Files\Python37\Scripts' 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:\Users\Administrator>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:\Users\Administrator>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>'

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.


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.


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:

  1. Install Python3.4:
    1. Download the last release of Python3.4 from the downloads page HERE
      • Direct link for Win32 MSI installer -> HERE
    2. Simply run the MSI to install python. It will register itself in the registry, and appear in Add/REmove Programs.
    3. 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
  2. Add the C:\python33\ and C:\python34\scripts 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).
  3. Install OpenSSL:
    1. Download Win32 OpenSSL page from HERE for your version of Windows and PC architecture
    2. Download Visual C++ 2008 redistributables for your version of Windows and PC architecture
    3. Download OpenSSL for your version of Windows and architecture (the regular version, not the light one)
    4. Add the c:\openssl-win32\bin (or similar) directory to your PATH, the same way you added C:\python34 and C:\python34\scripts above.
  4. Install Setuptools (get-pip.py should install Setuptools for you), but, just in case...
    1. Download ez_setup.py HERE and save it in C:\python34\scripts
    2. Run C:\python34\scripts> python ez_setup.py
  5. Install PIP
    1. Download get-pip.py from HERE and save it in C:\python34\scripts
    2. Run C:\python34\scripts> python get-pip.py
  6. Install LXML
    1. Download LXML 3.4.4 from HERE for your version of Windows and PC architecture
    2. Run the EXE file