Python lxml Module Installation Tutorial

Source: Internet
Author: User

This article mainly introduces the Python lxml module installation tutorial, this article explains the Windows system and Linux system installation tutorials, the need for friends can refer to the

lxml is the richest and easiest library in Python with XML and HTML-related features. lxml is not a python-brought package, but a python binding for the LIBXML2 and LIBXSLT libraries. What distinguishes it is that it takes into account the speed and functional integrity of these libraries, and the simplicity of the Pure Python API, which is compatible with the well-known ElementTree API but is superior to it! But the installation of lxml but also a little trouble, because there are dependencies, directly installed words with Easy_ Install, Pip can not succeed, will report gcc error. The following is a list of installation methods under Windows and Linux:

"Windows System"

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

1. Perform pip install virtualenv

The code is as follows:

C:>pip Install Virtualenv

Requirement already satisfied (use--upgrade to upgrade): Virtualenv in C:python27libsite-package

Svirtualenv-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, so 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. Implementation 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 to execute the command

The code is as follows:

Processing Lxml-2.3-py2.7-win-amd64.egg

Creating C:python27libsite-packageslxml-2.3-py2.7-win-amd64.egg

Extracting Lxml-2.3-py2.7-win-amd64.egg to C:python27libsite-packages

Adding lxml 2.3 to easy-install.pth file

Installed C:python27libsite-packageslxml-2.3-py2.7-win-amd64.egg

Processing dependencies for lxml==2.3

Finished processing dependencies for lxml==2.3

Note:

1. Available exe executable file, the method is simpler to install directly can

2. Available Easy_install installation method, also can use Pip way

The code is as follows:

#再执行下, the installation was successful!

>>> Import lxml

>>>

3. If installed with PIP, the common commands are:

The code is as follows:

Pip Install Simplejson # Install Python pack

Pip install--upgrade Simplejson # Upgrade Python pack

Pip Uninstall Simplejson # Uninstall Python pack

4. If using Eclipse+pydev development method, need to remove old package, reload once

The code is as follows:

Window--> Preferences--> PyDev--> # Otherwise, the guide pack will complain.

"Linux System"

Because lxml depends on the following package:

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

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.