Python lxml Module Installation Tutorial

Source: Internet
Author: User
lxml is the most abundant and easy-to-use library for XML and HTML-related features in Python. lxml is not a python-brought package, but a python binding for the LIBXML2 and LIBXSLT libraries. The difference is that it takes into account the speed and functional integrity of these libraries, as well as the simplicity of the Pure Python API, which is compatible with the familiar ElementTree API but is superior to the others! But install lxml but a bit of trouble, because there are dependencies, directly installed with Easy_install, Pip can not succeed, will report gcc error. Below is a list of installation methods for Windows and Linux:

"Windows System"

Make sure that Python is installed and the environment variables are configured, and the corresponding Easy_install and PIP are installed as well.

1. Execute pip Install virtualenv

The code is as follows:


C:\>pip Install Virtualenv
Requirement already satisfied (use--upgrade to upgrade): Virtualenv in C:\python27\lib\site-package
S\virtualenv-12.0.4-py2.7.egg

2. Download the lxml file that matches the system, Python version from the official website:
http://pypi.python.org/pypi/lxml/2.3/

Note:

For example, my computer is a Python 2.7.4, 64-bit operating system, then I can download
Lxml-2.3-py2.7-win-amd64.egg (MD5) # Python Egg
Or
Lxml-2.3.win-amd64-py2.7.exe (MD5) # MS Windows Installer

3. Execution of Easy_install Lxml-2.3-py2.7-win-amd64.egg
D:\downloads>easy_install Lxml-2.3-py2.7-win-amd64.egg # Enter the directory where the file is located execute the command

The code is as follows:


Processing Lxml-2.3-py2.7-win-amd64.egg
Creating C:\python27\lib\site-packages\lxml-2.3-py2.7-win-amd64.egg
Extracting Lxml-2.3-py2.7-win-amd64.egg to C:\python27\lib\site-packages
Adding lxml 2.3 to easy-install.pth file


Installed C:\python27\lib\site-packages\lxml-2.3-py2.7-win-amd64.egg
Processing dependencies for lxml==2.3
Finished processing dependencies for lxml==2.3

Note:

1. exe executable file can be used, the method is easier to install directly
2. Can be used Easy_install installation mode, or the way of PIP

The code is as follows:


#再执行下, the installation is successful!
>>> Import lxml
>>>

3. If you install with PIP, the common commands are:

The code is as follows:


Pip Install Simplejson # Install Python package
Pip install--upgrade Simplejson # Upgrade Python package
Pip Uninstall Simplejson # unload Python Package


4. If you use the Eclipse+pydev development method, you need to remove the old package, reload the

The code is as follows:


Window---Preferences--and PyDev--Interperter-python # Otherwise the guide will be error-

"Linux System"

Because lxml depends on the package as follows:

The code is as follows:


LIBXML2, Libxml2-devel, Libxlst, Libxlst-devel, PYTHON-LIBXML2, python-libxslt


So the installation steps are as follows:
First step: Install LIBXML2

The code is as follows:


$ sudo apt-get install libxml2 Libxml2-dev


Step Two: Install Libxslt

The code is as follows:


$ sudo apt-get install libxlst Libxslt-dev


Step three: Install PYTHON-LIBXML2 and PYTHON-LIBXSLT

The code is as follows:


$ sudo apt-get install PYTHON-LIBXML2 python-libxslt


Fourth Step: Install lxml

The code is as follows:


$ sudo easy_install lxml


Refer to the official documentation:
Http://codespeak.net/lxml/installation.html
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.