python中如何安装libxml2

按习惯使用pip install libxml2安装失败:
在这里插入图片描述
提示找不到叫 libxml2 的插件版本

1
2
3
4
5
6
7
8
ubuntu@VM-0-17-ubuntu:/usr/bin$ sudo pip install libxml2
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
WARNING: The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
ERROR: Could not find a version that satisfies the requirement libxml2 (from versions: none)
ERROR: No matching distribution found for libxml2

stackoverflow上找到的答案是:要这样安装:

1
2
3
sudo apt-get install libxml2-dev libxslt-dev python-dev

pip install lxml

https://stackoverflow.com/questions/38148460/pip-install-libxml2-failed

但为什么 pip install 的是 lxml 不是 libxml2?

还是找找官网:
在这里插入图片描述

在这里插入图片描述
官网第一句话即说明了:在python中libxml2叫lxml。
所以要用:pip install lxml 安装

官网地址:
http://xmlsoft.org/index.html
https://lxml.de/