将 lxml 安装到 virtualenv 中



我正在尝试在Windows 7上使用Python3.4的virtualenv中安装最新的lxml模块。作为一个长期的Linux用户,这个过程应该很简单,但当然,事实并非如此。我正在尝试安装最新的lxml,目前没有适用于Python3.4+的软件包因此,我获得了libxml2和libxslt,但我似乎无法识别它们。谁能指出我将所有内容链接在一起的正确方向。

我已经厌倦了 http://lxml.de/build.html 和我能想到的所有变体中的几乎所有东西。任何帮助将不胜感激。

错误日志如下:

Building lxml version 3.4.1.
Building with Cython 0.21.1.
ERROR: b"'xslt-config' is not recognized as an internal or external command,rnoperable program or batch file.rn"
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
missing cimport in module 'lxml.includes': srclxmllxml.etree.pyx
missing cimport in module 'lxml.includes.tree': srclxmllxml.etree.pyx
missing cimport in module 'lxml.python': srclxmllxml.etree.pyx
missing cimport in module 'lxml': srclxmllxml.etree.pyx
missing cimport in module 'lxml.includes': srclxmllxml.objectify.pyx
missing cimport in module 'lxml.includes.etreepublic': srclxmllxml.objectify.pyx
missing cimport in module 'lxml.includes.tree': srclxmllxml.objectify.pyx
missing cimport in module 'lxml': srclxmllxml.objectify.pyx
C:Python34Libdistutilsdist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
  warnings.warn(msg)
running build
running build_py
copying srclxmlincludeslxml-version.h -> buildlib.win32-3.4lxmlincludes
running build_ext
building 'lxml.etree' extension
C:minGWbingcc.exe -mdll -O -Wall -IC:UsersusernameDesktopangelScriptsdraftlxml-mastersrclxmlincludes -IC:Pyth
on34include -IC:Python34include -c srclxmllxml.etree.c -o buildtemp.win32-3.4Releasesrclxmllxml.etree.o -w
In file included from srclxmllxml.etree.c:239:0:
C:UsersusernameDesktopangelScriptsdraftlxml-mastersrclxmlincludes/etree_defs.h:14:31: fatal error: libxml/xmlvers
ion.h: No such file or directory
 #include "libxml/xmlversion.h"
                               ^
compilation terminated.
error: command 'C:\minGW\bin\gcc.exe' failed with exit status 1

我从Christoph的Gohlke's Python页面下载了lxml-3.4.4-cp34-none-win_amd64.whl并安装它

pip install lxml-3.4.4-cp34-none-win_amd64.whl 

它对我有用。

我建议从Christoph Gohlke的Python Extension Packages for Windows Repository下载lxml。选择"lxml‑3.4.1.win‑amd64‑py3.4.exe"或"lxml‑3.4.1.win32‑py3.4.exe",具体取决于您分别运行的是 64 位还是 32 位 Python 安装。不要运行安装程序,而是解压缩它。将生成的PLATLIB文件夹(lxml目录和lxml-3.4.1-py3.4.egg-info目录)的内容移动到 virtualenv 中的site-packages文件夹,您应该已全部设置好。

我刚刚遇到了这个问题,这是我解决它的方法:

首先尝试安装它。转到命令提示符并键入C:/Python34/Scripts/pip install lxml

如果您仍然遇到错误,请转到Christoph的Gohlke's Python页面

然后下载正确的 LXML。通常,由于我使用python 3.4并且我有一个Windows,因此我下载lxml-3.4.4-cp34-none-win32.whl

现在您有一个 whl 文件,请转到它所在的文件夹。在后台单击(因此未选择任何内容),然后同时左移 + 右键单击并单击打开命令窗口。然后键入C:/Python34/Scripts/pip install "NAME OF THE FILE OF YOUR JUST DOWNLOADED.whl"

,然后按回车键。这对我来说效果很好,输入报价后,您也可以按 tab,它应该为您填写正确的报价。

最新更新