爬虫项目须要用到lxml包,解析html文件,可是linux服务器没有lxml包,html
服务器中python版本是3.8.python
直接使用命令安装:linux
pip install lxml
中途会报错,错误提示我没有保存,懒得再现了。觉得是python版本问题,再运行:服务器
pip3 install lxml
注意此命令须要先安装pip3,但仍然报错。spa
多是线上包有问题,因而想经过安装whl文件,本地安装lxml。code
首先查看当前python可支持的whl文件:xml
python环境下运行:htm
import pip._internal print(pip._internal.pep425tags.get_supported())
又报错,说是没有.pep425tags属性,百度后发现,上面是AMD64运行代码,blog
下面是win32运行代码ip
import pip print(pip.pep425tags.get_supported())
而linux下(或者只要是python3)可以使用如下命令:
import wheel.pep425tags print(wheel.pep425tags.get_supported())
结果以下:
[('cp38', 'cp38m', 'linux_x86_64'), ('cp38', 'abi3', 'linux_x86_64'), ('cp38', 'none', 'linux_x86_64'),
('cp37', 'abi3', 'linux_x86_64'), ('cp36', 'abi3', 'linux_x86_64'), ('cp35', 'abi3', 'linux_x86_64'),
('cp34', 'abi3', 'linux_x86_64'), ('cp33', 'abi3', 'linux_x86_64'), ('cp32', 'abi3', 'linux_x86_64'),
('cp38', 'none', 'any'), ('cp3', 'none', 'any'), ('cp37', 'none', 'any'), ('cp36', 'none', 'any'),
('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'),
('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py3', 'none', 'linux_x86_64'), ('py38', 'none', 'any'),
('py3', 'none', 'any'), ('py37', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none', 'any'),
('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]
访问https://pypi.org/project/lxml/#files下载所须要的包,结果发现,竟然都不合适,只会提示此文件不匹配。
pip安装lxml
最后仍是经过pip安装,win下直接pip install lxml就完事了。linux不行,由于它有依赖,首先须要安装依赖:
yum install libxslt-devel
yum install libxml2
固然也许还须要别的依赖,这多是你的linux太菜,python环境得有吧,python-devel等等,仔细查看报错信息,安装必须的依赖