简体   繁体   English

在Windows 8.1上安装lxml,libxml2,libxslt

[英]Installing lxml, libxml2, libxslt on Windows 8.1

After additional exploration, I found a solution to installing lxml with pip and wheel. 经过额外的探索,我找到了一个解决方案,用pip和wheel安装lxml。 Additional comments on approach welcomed. 欢迎就方法提出补充意见。

I'm finding the existing Python documentation for Linux distributions excellent. 我发现Linux发行版的现有Python文档非常出色。 For Windows... not so much. 对于Windows ......不是那么多。 I've configured my Linux system fine but I need some help getting a Windows 8.1 tablet ready as well. 我已经配置好我的Linux系统,但我需要一些帮助才能准备好Windows 8.1平板电脑。

My project requires the lxml module for Python 3.4. 我的项目需要Python 3.4的lxml模块。 I've found many tutorials on how to install lxml but each has failed. 我发现了很多关于如何安装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. 任何帮助理解这应该如何工作,或者我做错了什么将不胜感激。

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. 在问题出现之前,我的“pip”安装工作正常。 I went to the Windows command line and made sure that "wheel" was installed. 我转到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/#lxml and 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. 我打开了PyCharm并且lxml模块可用。 I was able to execute the code without problem. 我能够毫无问题地执行代码。

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. 需要使用pip和wheel安装所需的模块(作为“* .whl”文件)。
  2. Using Dropbox to share a code folder with different PyCharm installations causes confusion for the "workspace.xml" file. 使用Dropbox与不同的PyCharm安装共享代码文件夹会导致“workspace.xml”文件混淆。 The two computers kept writing over each other, messing up the installation paths. 两台计算机一直在互相编写,弄乱了安装路径。

Hope this helps. 希望这可以帮助。

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的wheel文件:

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. 它立即安装。

I started working with lxml a little while ago, when there was a need to parse some html files. 不久前我开始使用lxml,当需要解析一些html文件时。 I somehow installed it and then after some time I lost the installation because of PC format. 我以某种方式安装它然后一段时间后因PC格式而丢失了安装。

Installing lxml on Windows from the available binaries/wheels is quite easy. 从可用的二进制文件/轮子在Windows上安装lxml非常简单。 The below link has the binaries/wheels in case you need them. 以下链接具有二进制文件/轮子,以备您需要时使用。

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-python and libxslt-devel , libxslt-python using pacman by issuing the below command. 如果你在Windows上使用git-sdk-win32,你可以先使用pacman通过发出以下命令来搜索libxml2-devellibxml2-pythonlibxslt-devellibxslt-python

pacman -Ss libxml2

and

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 lxml using the setup.py pip install lxml它可能无法构建轮子(就像它对我做的那样)但是会使用setup.py安装lxml

I simply have started loving this git-win32-sdk. 我只是开始喜欢这个git-win32-sdk。 It helps me work on my Windows with what I have learnt on Linux. 它帮助我使用我在Linux上学到的东西在Windows上工作。

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

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. 我在lxml 4.2.1中遇到了这个错误。 But it was fixed when I changed the requirement to lxml 4.2.5. 但是当我将要求更改为lxml 4.2.5时,它已得到修复。

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

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