我正在尝试使用 pip 安装 lxml。我有 Windows 11 和 Python 版本 python-3.10.2-amd64。我也在使用 Visual Studio Code (VSC)。我意识到我需要 lxml 从我的 VSC 终端中的错误消息:
Traceback (most recent call last):
File "Vegas.py", line 13, in <module>
soup = BeautifulSoup(html_text, 'lxml')
File "/usr/lib/python3.6/site-packages/bs4/__init__.py", line 248, in
__init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you
requested: lxml. Do you need to install a parser library?
从那里,我尝试使用 VSC 终端中的命令安装 lxml:
pip install lxml
我收到此错误消息:
Collecting lxml
Using cached lxml-4.7.1.tar.gz (3.2 MB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3.6 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ezhmqybu
cwd: /tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/
Complete output (3 lines):
Building lxml version 4.7.1.
Building without Cython.
Error: Please make sure the libxml2 and libxslt development packages are installed.
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/84/74/4a97db45381316cd6e7d4b1eb707d7f60d38cb2985b5dfd7251a340404da/lxml-4.7.1.tar.gz#sha256=a1613838aa6b89af4ba10a0f3a972836128801ed008078f8c1244e65958f1b24 (from https://pypi.org/simple/lxml/) (requires-python:>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, != 3.4.*). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Using cached lxml-4.6.5.tar.gz (3.2 MB)
于是我就去这个网站下载了libmxl2和libxslt:https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml https://www.lfd.uci.edu/%7Egohlke/pythonlibs/#lxml。下载 lxml-4.7.1-cp310-cp310-win_amd64.whl 版本(因为它与我的 python 版本匹配)后,我尝试在 Windows 命令提示符中使用以下命令:
pip install lxml-4.7.1-cp310-cp310-win_amd64.whl
我得到了这个结果:
lxml is already installed with the same version as the provided wheel.
Use --force-reinstall to force an installation of the wheel.
然后我执行了相同的命令,但添加了 --force-reinstall ,它表示已成功安装 lxml-4.7.1。然后我回到 VSC 终端,运行“pip install lxml”并收到与之前相同的错误消息。所以我在 VSC 终端中尝试了“pip install lxml-4.7.1-cp310-cp310-win_amd64.whl”命令并收到此错误:
ERROR: lxml-4.7.1-cp310-cp310-win_amd64.whl is not a supported wheel on this platform.
然后我想我应该尝试win32版本,因为我有Intel处理器。所以我在命令提示符下运行这个命令:
pip install lxml-4.7.1-cp310-cp310-win32.whl
我收到此错误消息:
ERROR: lxml-4.7.1-cp310-cp310-win32.whl is not a supported wheel on this platform.
所以我很茫然。任何帮助是极大的赞赏!