Monday, August 19, 2013

[Sharing] Install lxml on Windows Platform



Before you install lxml, you must install Libxml2 and Libxslt first.

1) Download Libxml2 and Libxslt :

But it’s a bit complicated to install Libxslt and Libxml2 module on windows platform with the original method.

Windows download link:

Version I download

2) Unzip Libxml2 and Libxslt :
Unzip them to your Python install root.
python3.3/Scripts/


3) Install pip :
[Python 3] Steps showing how to install pip on windows
4) Install lxml

Run "pip install lxml" at command promt.
 





 Copy the code to "lxml_sample.py" for test lxml work or not:

from lxml import etree
try:

  from lxml import etree
  print("running with lxml.etree")
except ImportError:
  try:
    # Python 2.5
    import xml.etree.cElementTree as etree
    print("running with cElementTree on Python 2.5+")
  except ImportError:
    try:
      # Python 2.5
      import xml.etree.ElementTree as etree
      print("running with ElementTree on Python 2.5+")
    except ImportError:
      try:
        # normal cElementTree install
        import cElementTree as etree
        print("running with cElementTree")
      except ImportError:
        try:
          # normal ElementTree install
          import elementtree.ElementTree as etree
          print("running with ElementTree")
        except ImportError:
          print("Failed to import ElementTree from any known place")
 

Run the python testing script :

No comments :

Post a Comment