在虚拟环境中安装lxml

3
我正在尝试在Windows 7上的Python3.4虚拟环境中安装最新的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,\r\noperable program or batch file.\r\n"
** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
missing cimport in module 'lxml.includes': src\lxml\lxml.etree.pyx
missing cimport in module 'lxml.includes.tree': src\lxml\lxml.etree.pyx
missing cimport in module 'lxml.python': src\lxml\lxml.etree.pyx
missing cimport in module 'lxml': src\lxml\lxml.etree.pyx
missing cimport in module 'lxml.includes': src\lxml\lxml.objectify.pyx
missing cimport in module 'lxml.includes.etreepublic': src\lxml\lxml.objectify.pyx
missing cimport in module 'lxml.includes.tree': src\lxml\lxml.objectify.pyx
missing cimport in module 'lxml': src\lxml\lxml.objectify.pyx
C:\Python34\Lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
  warnings.warn(msg)
running build
running build_py
copying src\lxml\includes\lxml-version.h -> build\lib.win32-3.4\lxml\includes
running build_ext
building 'lxml.etree' extension
C:\minGW\bin\gcc.exe -mdll -O -Wall -IC:\Users\username\Desktop\angelScripts\draft\lxml-master\src\lxml\includes -IC:\Pyth
on34\include -IC:\Python34\include -c src\lxml\lxml.etree.c -o build\temp.win32-3.4\Release\src\lxml\lxml.etree.o -w
In file included from src\lxml\lxml.etree.c:239:0:
C:\Users\username\Desktop\angelScripts\draft\lxml-master\src\lxml\includes/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
3个回答

3

我从 Christoph Gohlke的Python页面下载了lxml-3.4.4-cp34-none-win_amd64.whl并使用以下方法进行安装:

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

它对我有效。


2

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

首先尝试使用pip进行安装。打开命令提示符并输入 C:/Python34/Scripts/pip install lxml

如果您还是遇到错误,请访问Christoph's Gohlke's Python page

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

现在,您已经有了whl文件,请进入该文件所在的文件夹。单击背景(因此未选择任何内容),然后同时按下左Shift和右键,并单击打开命令窗口。然后输入 C:/Python34/Scripts/pip install "您刚刚下载的文件名.whl"

并按Enter键。这对我很有效,而且在输入引号后,您也可以按Tab键,它应该为您填充正确的引号。


2
我建议从Christoph Gohlke的Python扩展包 for Windows Repository下载lxml。根据您正在运行的Python版本是64位还是32位,选择lxml‑3.4.1.win‑amd64‑py3.4.exelxml‑3.4.1.win32‑py3.4.exe。不要运行安装程序,而是解压缩它。将结果中的PLATLIB文件夹(一个lxml目录和一个lxml-3.4.1-py3.4.egg-info目录)的内容移动到您的虚拟环境中的site-packages文件夹中,然后您就可以开始使用了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接