3.1-lxml installation

lxml is a parsing library of Python, supports the parsing of HTML and XML, supports XPath parsing, and the parsing efficiency is very high. In this section, let's take a look at the installation method of lxml, which is mainly introduced from the three major platforms of Windows, Linux and Mac.

1. Related Links

2. Installation under Windows

Under Windows, you can first try to install using pip, and then directly execute the following command:

pip3 install lxml

If there are no errors, the installation is successful.

If an error occurs, such as the lack of information such as the libxml2 library, you can use the wheel method to install.

It is recommended to go directly here (link: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml ) to download the corresponding wheel file, and find the local installed Python version and the corresponding lxml version of the system, such as Windows 64-bit , Python 3.6, choose lxml-3.8.0-cp36-cp36m-win_amd64.whl and download it to the local.

Then use pip to install, the command is as follows:

pip3 install lxml‑3.8.0‑cp36‑cp36m‑win_amd64.whl

So we can successfully install lxml.

3. Installation under Linux

The installation problem is not big under the Linux platform, you can also try pip installation first, the command is as follows:

pip3 install lxml

If you get an error, you can try the following solutions.

CentOS、Red Hat

For such systems, the error is mainly due to the lack of necessary libraries.

Execute the following command to install the required libraries:

sudo yum groupinstall -y development tools
sudo yum install -y epel-release libxslt-devel libxml2-devel openssl-devel

Mainly two libraries, libxslt-devel and libxml2-devel, lxml depends on them. After the installation is complete, try pip installation again.

Ubuntu、Debian和Deepin

In these systems, the reason for the error may also be the lack of necessary class libraries, execute the following command to install:

sudo apt-get install -y python3-dev build-essential libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev 
zlib1g-dev

After the installation is complete, try pip installation again.

4. Installation under Mac

On the Mac platform, you can still try pip installation first. The command is as follows:

pip3 install lxml

If an error occurs, you can execute the following command to install the necessary class library:

xcode-select --install

Then try pip installation again, there is no problem.

lxml is a very important library. The Beautiful Soup and Scrapy frameworks later need to use this library, so please be sure to install it successfully.

5. Verify the installation

After the installation is complete, you can test it under the Python command line:

$ python3
>>> import lxml

If no errors are reported, the library has been installed.

Guess you like

Origin blog.csdn.net/wu347771769/article/details/84071077