Install lxml on windows (on a virtualenv)

Lxml is a nice python library for XML processing. ETree is really quick, which makes things interesting if you have a large amount of XML files (or a bigger one) to process. Installation on linux/mac is painless (OK, you need homebrew on mac to make int painless, but you get my point…).

The other day I had to do it on windows. This is not really painless. I managed to do it, so here are the steps.


  • Python 2.7
  • VC++ 2880, the Express edition (freely downloadable from Microsoft), because python 2.7 is compiled against VS 2008
  • Create a virtual environment (e.g. in C:\Users\myuser\virtualenvs\myvenv). I’ll refer to this path as virtual_env_path later in the article.
  • In your virtual environment directory, create:
    • A directory PC (e.g. virtual_env_path\PC). This will contain the headers (equivalent to include).
    • A directory “PCbuild”. This will contain the libraries (equivalent to “lib”).

Installing dependencies

To be successful, you need to install several dependencies. The procedure is identical and it’s outlined below:

  1. Download the archive (.zip file). All archives have similar structure, typically containing directories named bin, lib and include
  2. Place the files in the archive’s include directory in the PC directory created above. Note that your path should read e.g. virtual_env_path\PC\libxml, not virtual_env_path\PC\include\libxml,
  3. Place the files of the lib directory in virtual_env_path\PCbuild.

Lxml has four dependencies which need to be installed following the steps described above:

  1. Install libxml from
  2. Install libxslt from
  3. Install zlib from gnu
  4. Install libiconv from gnu, namely the “developer files” zip. Important: copy “libiconv.lib” to “iconv.lib” in PCbuild.

Once this is done, you can install lxml in your virtual environment:

As a side note, you need to perform the following steps:

  • Get the default iconv archive, because it contains the .DLL file
  • Copy all contents of bin directories in downloaded archives to your virtual environment’s bin directory
  • copy the libiconv.dll to iconv.dll
  • copy all the .dll files in your virtual_env_path\Lib\site-packages\lxml. This is definitely not nice :(.

A little experiment: If you find this post and ad below useful, please check the ad out :-)

5 thoughts on “Install lxml on windows (on a virtualenv)

  1. Hey, thanks for the tutorial! It just worked for me, however I was confused with Step 4, I didn’t do the last part of it. However it worked flawlessly still.

  2. Could you explain the steps in the ‘side note’ a little more?

    “Copy all contents of bin directories in downloaded archives to your virtual environment’s bin directory” – we never made a bin directory in the previous steps

    “copy the libiconv.dll to iconv.dll” – where is this libiconv.dll file? I only have libiconv.dll.a

    “copy all the .dll files in your virtual_env_path\Lib\site-packages\lxml. This is definitely not nice :(.” – What is this virtual_env_path\Lib\site-packages\lxml? We never made it in the previous steps. Should we make this folder …\site-packages\lxml folder, and then take all the .dll files found in the PC and PCBuild folders, and copy them into …\lxml? Or how do you mean, “copy all the .dll files in your …\lxml”?

    Thank you very much for making these steps available for everyone. I hope they can help me :) So far it doesn’t work, but perhaps because I wasn’t able to follow the side note.

    1. I’ll take it point by point.

      • “Copy all contents…” – If you read the bits above, when you create a python virtual environment, it’ll create a “bin” directory inside that directory.
      • “copy libiconv.dll…” – The “developer files” zip has the dll files as well. If you go to sourceforge, you can find iconv 1.7, which has “iconv.dll”
      • “copy all the dll files…” – Once you install the python lxml, you should have the virtual_env_path\Lib\site-packages\lxml directory


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top