Installing the lxml module in Python

Source: Internet
Author: User

Installing the lxml module in Python

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. ExecutePip install virtualenv

  1. C: \> pip install virtualenv
  2. Requirement already satisfied (use -- upgrade to upgrade): virtualenv in c: \ python27 \ lib \ site-package
  3. S \ virtualenv-12.0.4-py2.7.egg
C:\>pip install virtualenvRequirement already satisfied (use --upgrade to upgrade): virtualenv in c:\python27\lib\site-packages\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

  1. Lxml-2.3-py2.7-win-amd64.egg (md5) # Python Egg
  2. Or
  3. Lxml-2.3.win-amd64-py2.7.exe (md5) # MS Windows installer
Lxml-2.3-py2.7-win-amd64.egg (md5) # Python eggor lxml-2.3.win-amd64-py2.7.exe (md5) # MS Windows installer

3. ExecuteEasy_install lxml-2.3-py2.7-win-amd64.egg

  1. 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
  2. Processing lxml-2.3-py2.7-win-amd64.egg
  3. Creating c: \ python27 \ lib \ site-packages \ lxml-2.3-py2.7-win-amd64.egg
  4. Extracting lxml-2.3-py2.7-win-amd64.egg to c: \ python27 \ lib \ site-packages
  5. Adding lxml 2.3 to easy-install.pth file
  6. Installed c: \ python27 \ lib \ site-packages \ lxml-2.3-py2.7-win-amd64.egg
  7. Processing dependencies for lxml = 2.3
  8. Finished processing dependencies for lxml = 2.3
D: \ Downloads> easy_install lxml-2.3-py2.7-win-amd64.egg # Go to the directory where the file is located and execute the command Processing lxml-2.3-py2.7-win-amd64.eggcreating c: \ python27 \ lib \ site-packages \ lxml-2.3-py2.7-win-amd64.eggExtracting lxml-2.3-py2.7-win-amd64.egg to c: \ python27 \ lib \ site-packagesAdding lxml 2.3 to easy-install.pth fileInstalled c: \ python27 \ lib \ site-packages \ lxml-2.3-py2.7-win-amd64.eggProcessing 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.

[Python] view plaincopyprint?
  1. # Run the following command to verify the installation!
  2. >>> Import lxml
  3. >>>
# Run the following command to complete the installation. >>> Import lxml >>>
3. for pip installation, Common commands are:
  • Pip install simplejson# Install the Python package
  • Pip install -- upgrade simplejson# Upgrade the Python package
  • Pip uninstall simplejson# Uninstall a Python package

 

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

 

  • Window --> Preferences --> PyDev --> Interperter-python# Otherwise, an error will be reported during package import.
[Linux system]

The packages that lxml depends on are as follows:

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

The installation steps are as follows:

Step 1: Install libxml2

  • $Sudo apt-get install libxml2 libxml2-dev
Step 2: Install libxslt
  • $Sudo apt-get install libxlst libxslt-dev 
Step 3: Install python-libxml2 and python-libxslt
  • $Sudo apt-get install python-libxml2 python-libxslt
Step 4: Install lxml
  • $Sudo easy_install lxml 

Refer to the official documentation:

Http://codespeak.net/lxml/installation.html

-------------------------------------- Split line --------------------------------------

Install Python3.4 on CentOS source code

Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]

Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]

Obtain Linux information using a Python script

Build a desktop algorithm transaction research environment using Python in Ubuntu

A Brief History of Python Development

Python details: click here
Python: click here

This article permanently updates the link address:

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.