简体   繁体   English

无法使用 pip 安装 lxml

[英]Failing to install lxml using pip

I am attempting to use pip to install lxml.我正在尝试使用 pip 来安装 lxml。 I have Windows 11 and Python version python-3.10.2-amd64.我有 Windows 11 和 Python 版本 python-3.10.2-amd64。 I am using Visual Studio Code (VSC) as well.我也在使用 Visual Studio Code (VSC)。 I realized I needed lxml from this error message in my VSC terminal:我从我的 VSC 终端中的错误消息中意识到我需要 lxml:

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?

From there, I tried to install lxml by using the command in the VSC terminal:从那里,我尝试使用 VSC 终端中的命令安装 lxml:

pip install lxml

And I got this error message:我收到此错误消息:

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)

So I went to this website to download libmxl2 and libxslt: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml .于是去这个网站下载了libmxl2和libxslt: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml After downloading the lxml‑4.7.1‑cp310‑cp310‑win_amd64.whl version (since it matched my python version) I tried using the following command in the windows command prompt:下载 lxml‑4.7.1‑cp310‑cp310‑win_amd64.whl 版本后(因为它与我的 python 版本匹配)我尝试在 windows 命令提示符下使用以下命令:

pip install lxml-4.7.1-cp310-cp310-win_amd64.whl

And I got this result:我得到了这个结果:

lxml is already installed with the same version as the provided wheel. 
Use --force-reinstall to force an installation of the wheel.

So then I did the same command but added the --force-reinstall and it said it successfully installed lxml-4.7.1.然后我执行了相同的命令,但添加了 --force-reinstall,它说它成功安装了 lxml-4.7.1。 Then I went back to the VSC terminal, ran "pip install lxml" and got the same error message as I did before.然后我回到 VSC 终端,运行“pip install lxml”并收到与之前相同的错误消息。 So I tried the "pip install lxml-4.7.1-cp310-cp310-win_amd64.whl" command in the VSC terminal and got this error:所以我在 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.

Then I thought that I should try the win32 version since I have an Intel processor.然后我认为我应该尝试 win32 版本,因为我有一个 Intel 处理器。 So I run this command in the command prompt:所以我在命令提示符下运行这个命令:

pip install lxml-4.7.1-cp310-cp310-win32.whl

And I get this error message:我收到此错误消息:

ERROR: lxml-4.7.1-cp310-cp310-win32.whl is not a supported wheel on this platform.

So I'm at a loss.所以我很茫然。 Any help is greatly appreciated!任何帮助是极大的赞赏!

I am using windows 11 and python 3.11 so for the easy solution first I downloaded the latest 'lxml-4.9.0-cp311-cp311-win_amd64.whl' from the https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml我正在使用 windows 11 和 python 3.11 所以为了简单的解决方案,我首先从 https 下载最新的“lxml-4.9.0-cp311-cp311-win_amd64.whl” ://www.lfd.uci.edu/~gohlke/ pythonlibs/#lxml

Then copied it to my user folder which is "C:\Users\memon"然后将其复制到我的用户文件夹“C:\Users\memon”

And then run this command from the terminal:然后从终端运行这个命令:

pip install lxml-4.9.0-cp311-cp311-win_amd64.whl

And it successfully installed 'lxml' on my windows 11 without any errors.它成功地在我的 windows 11 上安装了“lxml”,没有任何错误。

Previously I was facing 'C++ 14.0 or greater is required' error for the same 'lxml' install which I resolved with this thread: https://stackoverflow.com/a/64262038/14957324以前,对于我使用此线程解决的相同“lxml”安装,我面临“需要 C++ 14.0 或更高版本”错误: https://stackoverflow.com/a/64262038/14957324

Try with the last wheels on https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml corresponding to your 3.10 version.尝试使用与您的 3.10 版本对应的https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml上的最后一个轮子。 It worked for me它对我有用

The solution provided by JUNED MEMON above worked for me.上面 JUNED MEMON 提供的解决方案对我有用。

pip install lxml-4.9.0-cp311-cp311-win_amd64.whl

I discovered after much misery that "p311" indicates python version 3.11 and that the download must exactly match the python version in use.在经历了很多痛苦之后,我发现“p311”表示 python 版本 3.11,并且下载必须与正在使用的 python 版本完全匹配。

I was also facing the same problem.我也面临着同样的问题。 Later what i did is:后来我做的是:

1st step: in cmd panel i did "pip install numpy" (you can skip if it is already installed".第一步:在 cmd 面板中我执行了“pip install numpy”(如果已经安装可以跳过)。

2nd step: in cmd panel I did "pip install mkl"第二步:在 cmd 面板中我做了“pip install mkl”

3rd step: i downloaded "lxml-4.9.0-cp311-cp311-win_amd64.whl" this file from website: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml .第三步:我从网站下载了“lxml-4.9.0-cp311-cp311-win_amd64.whl”这个文件: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml The reason for choosing this file is my python version is 3.11.00 and window is 64 bytes.选择这个文件的原因是我的python版本是3.11.00,window是64字节。

4th step: i then copied the "lxml-4.9.0-cp311-cp311-win_amd64.whl" file to "documents" folder from download folder第 4 步:然后我将“lxml-4.9.0-cp311-cp311-win_amd64.whl”文件从下载文件夹复制到“文档”文件夹

5th step: in cmd panel i typed "cd documents" to navigate to documents folder(where i have just stored the file "lxml-4.9.0-cp311-cp311-win_amd64.whl").第 5 步:在 cmd 面板中,我键入“cd 文档”以导航到文档文件夹(我刚刚存储文件“lxml-4.9.0-cp311-cp311-win_amd64.whl”)。

6th step: then i run pip install lxml-4.9.0-cp311-cp311-win_amd64.whl (in your case replace "lxml-4.9.0-cp311-cp311-win_amd64.whl" by the file name you downloaded) then finally lxml file is installed.第 6 步:然后我运行 pip install lxml-4.9.0-cp311-cp311-win_amd64.whl(在你的情况下用你下载的文件名替换“lxml-4.9.0-cp311-cp311-win_amd64.whl”)然后最后lxml 文件已安装。

Actually i was trying to install "pytrends".实际上我正在尝试安装“pytrends”。 for that lxml was required so after installing lxml i then installed pytrends using command "pip install pytrends".因为需要 lxml 所以在安装 lxml 之后我使用命令“pip install pytrends”安装了 pytrends。 I hope this will work for you.我希望这对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM