Python 在 Windows 8.1 上安装 lxml、libxml2、libxslt

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30493031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:32:03  来源:igfitidea点击:

Installing lxml, libxml2, libxslt on Windows 8.1

pythonwindowsmoduleinstallationlxml

提问by SigmaXD

After additional exploration, I found a solution to installing lxml with pip and wheel. Additional comments on approach welcomed.

经过额外的探索,我找到了一个用pip和wheel安装lxml的解决方案。欢迎对方法提出更多意见。

I'm finding the existing Python documentation for Linux distributions excellent. For Windows... not so much. I've configured my Linux system fine but I need some help getting a Windows 8.1 tablet ready as well.

我发现 Linux 发行版的现有 Python 文档非常好。对于 Windows... 没有那么多。我已经很好地配置了我的 Linux 系统,但我还需要一些帮助来准备好 Windows 8.1 平板电脑。

My project requires the lxml module for Python 3.4. I've found many tutorials on how to install lxml but each has failed.

我的项目需要 Python 3.4 的 lxml 模块。我找到了很多关于如何安装 lxml 的教程,但每个教程都失败了。

https://docs.python.org/3/installing/I've downloaded the "get-pip.py" and successfully ran it from the Windows cmd line with the result:

https://docs.python.org/3/installing/我已经下载了“get-pip.py”并从 Windows cmd 行成功运行了它,结果是:

Requirement already up-to-date: pip in c:\python34\lib\site-packages

So I don't think that I have a "pip" problem. From there I've run the following from the Windows cmd line:

所以我不认为我有“点子”问题。从那里我从 Windows cmd 行运行以下命令:

python -m pip install lxml

A long list of commands scroll through but there are a couple of lines that appear to be errors that I'm unable to resolve.

一长串命令滚动显示,但有几行似乎是我无法解决的错误。

  ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
  ** make sure the development packages of libxml2 and libxslt are installed **

and

Failed building wheel for lxml

And the last part, all in red

最后一部分,全部为红色

Command "C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\Users\Owner\AppData\Local\Temp\pip-build-ya3n6wkd\lxml\setup.py';exec(compi
le(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Owner\AppData\Local\Temp\pip-ytybzl9l-r
ecord\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Owner\AppData\Local\Temp\pip-build-ya3n6wkd\lxml

Any assistance in understanding how this should work, or what I'm doing wrong would be greatly appreciated.

任何帮助理解这应该如何工作,或者我做错了什么,将不胜感激。

采纳答案by SigmaXD

I was able to fix the installation with the following steps. I hope others find this helpful.

我能够通过以下步骤修复安装。我希望其他人觉得这很有帮助。

My installation of "pip" was working fine before the problem. I went to the Windows command line and made sure that "wheel" was installed.

在出现问题之前,我的“pip”安装工作正常。我转到 Windows 命令行并确保安装了“wheel”。

C:\Python34>python -m pip install wheel
Requirement already satisfied (use --upgrade to upgrade): wheel in c:\python34\lib\site-packages

After that I downloaded the lxml file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxmland placed it in my python directory "C:\Python34"

之后,我从http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml下载了 lxml 文件并将其放在我的 python 目录“C:\Python34”中

In that directory I ran the following:

在该目录中,我运行了以下命令:

C:\Python34>python -m pip install lxml-3.4.4-cp34-none-win32.whl

The results were:

结果是:

Processing c:\python34\lxml-3.4.4-cp34-none-win32.whl
Installing collected packages: lxml
Successfully installed lxml-3.4.4

I opened PyCharm and lxml module was available. I was able to execute the code without problem.

我打开了 PyCharm 并且 lxml 模块可用。我能够毫无问题地执行代码。

What I learned (though this may be corrected by others more knowledgeable)

我学到的东西(虽然这可能会被其他知识渊博的人纠正)

  1. Need to install the desired module (as a "*.whl" file) using pip and wheel.
  2. Using Dropbox to share a code folder with different PyCharm installations causes confusion for the "workspace.xml" file. The two computers kept writing over each other, messing up the installation paths.
  1. 需要使用 pip 和 wheel 安装所需的模块(作为“*.whl”文件)。
  2. 使用 Dropbox 与不同的 PyCharm 安装共享代码文件夹会导致“workspace.xml”文件混淆。两台电脑不停地互相写入,把安装路径弄乱了。

Hope this helps.

希望这可以帮助。

回答by RockAndRoleCoder

My situation was a lot like this. I have Python 3.4 installed on my Laptop for work, and we're in a tight security, so I can't just install 3.5 without getting system admin to do it.

我的情况很像这样。我在我的笔记本电脑上安装了 Python 3.4 用于工作,我们处于严密的安全状态,所以我不能在没有系统管理员的情况下安装 3.5。

So I hit up Python Extension site here:

所以我在这里点击了 Python 扩展站点:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

Pulled the wheel file for lxml that matched my specs:

拉出与我的规格相匹配的 lxml 的轮文件:

lxml-3.6.4-cp34-cp34m-win_amd64.whl

And then just typed:

然后输入:

pip install lxml-3.6.4-cp34-cp34m-win_amd64.whl

And it installed right away.

它立即安装。

回答by h3xh4wk

I started working with lxml a little while ago, when there was a need to parse some html files. I somehow installed it and then after some time I lost the installation because of PC format.

不久前我开始使用 lxml,当时需要解析一些 html 文件。我以某种方式安装了它,然后由于 PC 格式,一段时间后我丢失了安装。

Installing lxml on Windows from the available binaries/wheels is quite easy. The below link has the binaries/wheels in case you need them.

从可用的二进制文件/轮子在 Windows 上安装 lxml 非常容易。下面的链接有二进制文件/轮子,以防你需要它们。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

After downloading the wheel file as per your Windows you can issue the below command pip install <pathtoyourdownloadedwheelfile>

根据您的 Windows 下载车轮文件后,您可以发出以下命令 pip install <pathtoyourdownloadedwheelfile>

And In case you are using git-sdk-win32 for Windows, You can first search the libxml2-devel,libxml2-pythonand libxslt-devel, libxslt-pythonusing pacmanby issuing the below command.

如果您在 Windows 上使用 git-sdk-win32,您可以首先通过发出以下命令搜索libxml2-devel,libxml2-pythonlibxslt-devel,libxslt-python使用pacman

pacman -Ss libxml2

pacman -Ss libxml2

and

pacman -Ss libxslt

pacman -Ss libxslt

then you can install lxml using the below command

然后您可以使用以下命令安装 lxml

pip install lxml It might fail to build the wheel(as it did for me) but will install lxmlusing the setup.py

pip install lxml 它可能无法构建轮子(就像对我所做的那样)但会lxml使用setup.py

I simply have started loving this git-win32-sdk. It helps me work on my Windows with what I have learnt on Linux.

我只是开始喜欢这个 git-win32-sdk。它帮助我利用我在 Linux 上学到的知识在 Windows 上工作。

https://github.com/git-for-windows/build-extra/releases

https://github.com/git-for-windows/build-extra/releases

回答by Roger Iyengar

This issue appears to be fixed as of lxml version 4.2.5.

从 lxml 版本 4.2.5 开始,此问题似乎已得到修复。

If you're still getting this error and you're specifying a specific version of lxml in a requirements file, try updating the requirements file to specify lxml version 4.2.5 or above.

如果您仍然遇到此错误并且您在需求文件中指定了特定版本的 lxml,请尝试更新需求文件以指定 lxml 版本 4.2.5 或更高版本。

I had this error with lxml 4.2.1. But it was fixed when I changed the requirement to lxml 4.2.5.

我在 lxml 4.2.1 上遇到了这个错误。但是当我将要求更改为 lxml 4.2.5 时它被修复了。