2010-06-15 23 views
33

我想在Windows 64位机器上为Python 2.7构建lxml。我找不到Python 2.7版本的lxml egg。所以我从源头上编译它。我下面这个网站在Windows上构建用于Python 2.7的lxml

http://lxml.de/build.html

下静态链接一节。我得到错误

C:\Documents and Settings\Administrator\Desktop\lxmlpackage\lxml-2.2.6\lxml-2.2. 
6>python setup.py bdist_wininst --static 
Building lxml version 2.2.6. 
NOTE: Trying to build without Cython, pre-generated 'src/lxml/lxml.etree.c' need 
s to be available. 
ERROR: 'xslt-config' is not recognized as an internal or external command, 
operable program or batch file. 

** make sure the development packages of libxml2 and libxslt are installed ** 

Using build configuration of libxslt 
Building against libxml2/libxslt in one of the following directories: 
    ..\libxml2-2.7.6--win32--w2k--x64\lib 
    ..\libxslt-1.1.26--win32--w2k--x64--0002\lib 
    ..\zlib-1.2.4--win32--w2k--x64 
    ..\iconv-1.9.1--win32--w2k--x64-0001\lib 
running bdist_wininst 
running build 
running build_py 
running build_ext 
building 'lxml.etree' extension 
error: Unable to find vcvarsall.bat 

任何人都可以帮助我吗?我试着设置路径有微软的V​​isual Studio .. 我可以从命令行运行vcvarsall.bat ..但是Python是有问题

+8

如果你碰巧使用AMD64,你可以试试这些:http://www.lfd.uci。埃杜/〜gohlke/pythonlibs/ – ChristopheD 2010-06-15 17:46:20

+0

@Christo你有说明的地方你如何生成的这些可执行文件? – Kamal 2010-06-15 19:20:54

+1

我没编译这些,所以做的最好的事情是与作者联系:http://www.lfd.uci.edu/~gohlke/你用什么 – ChristopheD 2010-06-15 21:46:56

回答

58

我敢打赌,你不使用VS 2008这个:)

def find_vcvarsall(version):功能(你猜怎么着,它看起来vcvarsall.bat)中的distutils用下面的评论

At first it tries to find the productdir of VS 2008 in the registry. If that fails it falls back to the VS90COMNTOOLS env var.

如果你不使用VS 2008,那么你既没有注册表项,也没有合适的环境变量,这就是为什么的distutils找不到vcvarsall.bat文件。它确实而不是检查bat文件是否可通过PATH环境变量到达。

解决方案是将VS90COMNTOOLS变量定义为指向Visual Studio的Tools目录。

如此说来看一看在Python的文档11.4. distutils.msvccompiler — Microsoft Compiler部分,其规定

Typically, extension modules need to be compiled with the same compiler that was used to compile Python.

马丁诉Loewis在python-list邮件列表上的标题Download Visual Studio Express 2008 now电子邮件声明相同

Python 2.6, 2.7, and 3.1 are all built with that release (i.e. 2008). Because of another long tradition, Python extension modules must be built with the same compiler version (more specifically, CRT version) as Python itself. So to build extension modules for any of these releases, you need to have a copy of VS 2008 or VS 2008 Express.

根据以上陈述,应该使用VS 2008,如果你想为Python 2.7构建lxml,尽管设置VS90COMNTOOLS负责找到vcvarsall.bat文件, s不是解决方案。

话虽这么说:)人都试图用旧的CRT与新的编译器:
Can I use Visual Studio 2010's C++ compiler with Visual Studio 2008's C++ Runtime Library?
How to Enforce C++ compiler to use specific CRT version?
VS 2008 - Link against older C runtime

我要感谢千电子伏德怀尔(为指出的VS版本的重要性在lxml邮件列表中的线程Problem building lxml under Windows - error: Unable to find vcvarsall.bat中使用)和Stefan Behnel(用于指示我将distutils作为处理编译器配置的地方)。我还想感谢agronholm来自freenode #distutils IRC频道,以确认distutils确实包含查找vcvarsall.bat文件的代码。

+16

好的,你解释了它,但在没有VS2008的情况下需要做什么? – Maysam 2012-09-17 11:13:43

+0

@Maysam你**不应该**使用除Visual Studio 2008以外的其他任何东西。 – 2012-09-17 13:46:34

+30

确定很长很长的答案...但它仍不能解释如何真正解决这个人遇到的问题? – 2012-10-21 21:44:01

4

以下推荐的解决方案后:

  1. 从微软下载VCForPython27.msi
  2. 安装它(Win7的,Python的(X,Y)2.7。9 32位),
  3. 进入/更新环境变量VS90COMNTOOLS到 安装目录值(C:\ Program Files文件(x86)的\共同 文件\微软\的Visual C++为Python \ 9.0)

我的问题仍然存在(想要在C中构建Python扩展)。

我不得不做以下两个令人难以置信的肮脏的调整,之前的一切现在确实工作:

  1. 修改“msvc9compiler.py”“C:\ Python27 \ LIB \ distutils的”, 功能find_vcvarsall,到现在指向“可视C++对 的Python”而不是到“VC”
  2. 复制下的目录创始人 “C:\ Program Files文件(x86)的\共同 文件\微软\的Visual C++为Python \ 9.0 \”“C:\ Program Files文件 (86)\ Common Files文件\ Microsoft \ Visual C++ for Python \“(即一个目录 级别)。

我不能告诉谁在这里做一些错误的 - 也许一

编辑。移动目录因为this distutils bug中描述的问题而起作用。

even if VS90COMNTOOLS is set, msvc9compiler isn't able to find vcvarsall.bat because it is installed in %installdir%/vcvarsall.bat and not %installdir%/VC/vcvarsall.bat

所描述的解决方法是使用Visual C++命令提示符:

  1. Enter MSVC for Python command prompt

  2. SET DISTUTILS_USE_SDK=1

  3. SET MSSdk=1

  4. python.exe setup.py ...

3

Jorj麦基几乎是正确的:确实安装VCForPython27.msi是不够的,而且是存在的distutils的问题,它防止从找到find_vcvarsall。事实上,这个问题并不是直接引起争议,而是关于如何打包VCForPython27.msi以及如何放置vcvarsall.bat(文件夹布局与VS2008 SDK不同)。

一个简单的解决方法,同时这可能在Python 2.7.11补丁:使用setuptools而不是distutils。

另一个手动解决方法,如果你坚持的distutils:

1) Enter MSVC for Python command prompt 
2) SET DISTUTILS_USE_SDK=1 
3) SET MSSdk=1 
4) you can then build your C extensions: python.exe setup.py ... 

错误报告和解决方法由格雷戈里Szorc: http://bugs.python.org/issue23246

更多信息以及使用%%用Cython内IPython的魔力一种变通方法: https://github.com/cython/cython/wiki/CythonExtensionsOnWindows