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
- 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
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
- Lxml-2.3-py2.7-win-amd64.egg (md5) # Python Egg
- Or
- 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
- 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
- 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
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?
- # Run the following command to verify the installation!
- >>> Import lxml
- >>>
# 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
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: