Python lxml module installation tutorial

Source: Internet
Author: User
Tags virtualenv

Python lxml module installation tutorial

This article mainly introduces the installation tutorial of the Python lxml module. This article explains the installation tutorials for Windows and Linux systems respectively. For more information, see

Lxml is the most abundant and easy-to-use library in Python related to XML and HTML functions. Lxml is not a Python package, but a Python-based binding between libxml2 and libxslt libraries. What makes it different is that it takes into account the speed and functional integrity of these libraries, as well as the simplicity of pure Python APIs. It is compatible with the well-known ElementTree API, but is superior to it! However, installing lxml is a little troublesome. Because of the dependency, if you install lxml directly, easy_install and pip cannot succeed, and a gcc error will be reported. The installation methods for Windows and Linux are listed below:

[Windows]

Make sure that Python has been installed, environment variables have been configured, and the corresponding easy_install and pip have been installed.

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 and Python version from the official website:

Http://pypi.python.org/pypi/lxml/2.3/

NOTE:

For example, if my computer is Python 2.7.4 and a 64-bit operating system, you 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. Execute the easy_install lxml-2.3-py2.7-win-amd64.egg

D: \ Downloads> easy_install lxml-2.3-py2.7-win-amd64.egg # Go to the directory where the file is located and run 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. the exe executable file is available, which can be installed simply and directly.

2. The installation method can be easy_install or pip.

The Code is as follows:

# Run the following command to verify the installation!

>>> Import lxml

>>>

3. for pip installation, Common commands are:

The Code is as follows:

Pip install simplejson # install the Python package

Pip install -- upgrade simplejson # upgrade Python package

Pip uninstall simplejson # uninstall the Python package

4. If you use Eclipse + Pydev for development, you need to remove the old package and reload it once.

The Code is as follows:

Window --> Preferences --> PyDev --> Interperter-python # Otherwise, an error is returned when importing a package.

[Linux system]

The packages that lxml depends on are as follows:

The Code is as follows:

Libxml2, libxml2-devel, libxlst, libxlst-devel, python-libxml2, python-libxslt

The installation steps are as follows:

Step 1: Install libxml2

The Code is as follows:

$ Sudo apt-get install libxml2 libxml2-dev

Step 2: Install libxslt

The Code is as follows:

$ Sudo apt-get install libxlst libxslt-dev

Step 3: Install python-libxml2 and python-libxslt

The Code is as follows:

$ Sudo apt-get install python-libxml2 python-libxslt

Step 4: 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.