简体   繁体   English

如何在Windows机器上的Python 3.4中安装lxml

[英]How to install lxml in Python 3.4 on Windows machine

I've been spending hours on this. 我一直在花这些时间。 I'm new to Python and can't see what the solution may be. 我是Python的新手,无法看到解决方案可能是什么。

I have Python 3.4 and want to work with .docx , which requires lxml . 我有Python 3.4,并希望使用.docx ,它需要lxml

The workflow I've done so far is: I go to the Python lxml package installer page, but it's quite confusing to know which version I need. 到目前为止我所做的工作流程是:我转到Python lxml软件包安装程序页面,但知道我需要哪个版本却很困惑。 I tried with several of them that contained the 34 numbers, both .exe and .tar . 我试过其中几个包含34个数字,包括.exe.tar I also tried pip install lxml3.4.4 and pip install lxml 3.4.4 . 我也试过pip install lxml3.4.4pip install lxml 3.4.4 None of them worked either. 他们都没有工作。

This is what the command prompt says when I did pip install lxml (it automatically grabs the lxml 3.4.4 I've downloaded and then prints what you can see in the screenshot): 当我执行pip install lxml时,这就是命令提示符所说的pip install lxml (它会自动抓取我下载的lxml 3.4.4然后打印出你在屏幕截图中看到的内容):

问题截图。什么命令提示符返回

What am I doing wrong and what can I do to repair it? 我做错了什么,我该怎么做才能修复它? And/or what exact version of lxml do I need to install from where? 和/或我需要从哪里安装lxml的确切版本? I am really discouraged that this is so difficult. 我真的很沮丧,这太难了。 Thanks 谢谢

As said at the lxml homepage , it happened to you: 正如在lxml主页上所说,它发生在你身上:

If you fail to build lxml on your MS Windows system from the signed and tested sources that we release, consider using the binary builds from PyPI or the unofficial Windows binaries that Christoph Gohlke generously provides. 如果您无法在我们发布的已签名和测试的源上在MS Windows系统上构建lxml,请考虑使用PyPI的二进制构建或Christoph Gohlke慷慨提供的非官方Windows二进制文件。

So you have to download the right wheel file from Unofficial Windows Binaries for Python Extension Packages . 因此,您必须从Unofficial Windows Binaries for Python Extension Packages下载右轮文件。

Step 1: Download appropriate version 第1步:下载适当的版本

Depending on your machine you have to download the wheel file lxml‑3.4.4‑cp34‑none‑win32.whl or lxml‑3.4.4‑cp34‑none‑win_amd64.whl , because you want the version for Python3.4 (that's the 34 in cp34). 根据你的机器,你必须下载轮文件lxml-3.4.4-cp34-none-win32.whllxml-3.4.4-cp34-none-win_amd64.whl ,因为你想要Python3.4的版本(那是cp34中的34 )。

Step 2: Open cmd and navigate to the download folder 第2步:打开cmd并导航到下载文件夹

I have chosen to open the cmd in administrator mode. 我选择以管理员模式打开cmd。 But this is probably not necessary for you. 但这可能不适合你。

Step 3: Install wheel file with pip 第3步:使用pip安装wheel文件

Now you have to install the unofficial wheel file with pip. 现在你必须用pip安装非官方的wheel文件。 Maybe you can do pip install pip --upgrade before you install the wheel file. 也许你可以在安装wheel文件之前做pip install pip --upgrade But this is probably also not necessary for you. 但这对您来说可能也没有必要。 To do the installation, just type pip install <downloaded_file> . 要进行安装,只需键入pip install <downloaded_file>

Or as cgohlke mentioned in his comment to your question: If you can't do pip install in cmd directly, this is what you can try: C:\\Python34\\python.exe -m pip install <downloaded_file> . 或者正如cgohlke在他对你的问题的评论中提到的:如果你不能直接在cmd中执行pip install ,那么你可以尝试: C:\\Python34\\python.exe -m pip install <downloaded_file> You have to edit the path if Python3.4 is installed elsewhere, of course. 当然,如果Python3.4安装在别处,你必须编辑路径。

Don't panic. 不要惊慌。 If you try to install the wrong downloaded file (eg win32 instead of amd64 ), it shouldn't break anything. 如果您尝试安装错误的下载文件(例如win32而不是amd64 ),它不应该破坏任何东西。 An error message should occur: <package name> is not a supported wheel on this platform . 应出现错误消息: <package name> is not a supported wheel on this platform

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

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