使用 pip 安装 lxml 失败

Bam*_*rey 6 python lxml python-wheel

我正在尝试使用 pip 安装 lxml。我有 Windows 11 和 Python 版本 python-3.10.2-amd64。我也在使用 Visual Studio Code (VSC)。我意识到我需要 lxml 从我的 VSC 终端中的错误消息:

\n
Traceback (most recent call last):\nFile "Vegas.py", line 13, in <module>\nsoup = BeautifulSoup(html_text, \'lxml\')\nFile "/usr/lib/python3.6/site-packages/bs4/__init__.py", line 248, in \n__init__\n% ",".join(features))\nbs4.FeatureNotFound: Couldn\'t find a tree builder with the features you \nrequested: lxml. Do you need to install a parser library?\n
Run Code Online (Sandbox Code Playgroud)\n

从那里,我尝试使用 VSC 终端中的命令安装 lxml:

\n
pip install lxml\n
Run Code Online (Sandbox Code Playgroud)\n

我收到此错误消息:

\n
Collecting lxml\n  Using cached lxml-4.7.1.tar.gz (3.2 MB)\n  Preparing metadata (setup.py) ... error\n  ERROR: Command errored out with exit status 1:\n   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\n       cwd: /tmp/pip-install-xgwntbxb/lxml_73c33ff5c1614a6da59bbd9f3017fa5c/\n  Complete output (3 lines):\n  Building lxml version 4.7.1.\n  Building without Cython.\n  Error: Please make sure the libxml2 and libxslt development packages are installed.\n  ----------------------------------------\nWARNING: 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.\n  Using cached lxml-4.6.5.tar.gz (3.2 MB)\n
Run Code Online (Sandbox Code Playgroud)\n

所以我去这个网站下载libmxl2和libxslt:https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml。下载 lxml\xe2\x80\x914.7.1\xe2\x80\x91cp310\xe2\x80\x91cp310\xe2\x80\x91win_amd64.whl 版本(因为它与我的 python 版本匹配)后,我尝试在 Windows 中使用以下命令命令提示符:

\n
pip install lxml-4.7.1-cp310-cp310-win_amd64.whl\n
Run Code Online (Sandbox Code Playgroud)\n

我得到了这个结果:

\n
lxml is already installed with the same version as the provided wheel. \nUse --force-reinstall to force an installation of the wheel.\n
Run Code Online (Sandbox Code Playgroud)\n

然后我执行了相同的命令,但添加了 --force-reinstall ,它表示已成功安装 lxml-4.7.1。然后我回到 VSC 终端,运行“pip install lxml”并收到与之前相同的错误消息。所以我在 VSC 终端中尝试了“pip install lxml-4.7.1-cp310-cp310-win_amd64.whl”命令并收到此错误:

\n
ERROR: lxml-4.7.1-cp310-cp310-win_amd64.whl is not a supported wheel on this platform.\n
Run Code Online (Sandbox Code Playgroud)\n

然后我想我应该尝试win32版本,因为我有Intel处理器。所以我在命令提示符下运行这个命令:

\n
pip install lxml-4.7.1-cp310-cp310-win32.whl\n
Run Code Online (Sandbox Code Playgroud)\n

我收到此错误消息:

\n
ERROR: lxml-4.7.1-cp310-cp310-win32.whl is not a supported wheel on this platform.\n
Run Code Online (Sandbox Code Playgroud)\n

所以我很茫然。任何帮助是极大的赞赏!

\n

小智 8

我使用的是 windows 11 和 python 3.11,因此为了简单的解决方案,我首先从https://www.lfd.uci.edu/~gohlke/下载了最新的“lxml-4.9.0-cp311-cp311-win_amd64.whl” pythonlibs/#lxml

然后将其复制到我的用户文件夹“C:\Users\memon”

然后从终端运行此命令:

pip install lxml-4.9.0-cp311-cp311-win_amd64.whl
Run Code Online (Sandbox Code Playgroud)

它在我的 Windows 11 上成功安装了“lxml”,没有任何错误。

以前,我在同一“lxml”安装中遇到“需要 C++ 14.0 或更高版本”错误,我通过此线程解决了该错误: https: //stackoverflow.com/a/64262038/14957324

  • 这对我有用。我还使用 Windows 11 和 Python 3.11 (2认同)

小智 0

尝试使用https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml上与您的 3.10 版本相对应的最后一个轮子。这对我有用