在Windows上为Python 2.7构建lxml [英] Building lxml for Python 2.7 on Windows

查看:93
本文介绍了在Windows上为Python 2.7构建lxml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows 64位计算机上为Python 2.7构建lxml.我找不到适用于Python 2.7版本的lxml egg.因此,我正在从源代码进行编译.我正在按照此网站上的说明进行操作

I am trying to build lxml for Python 2.7 on Windows 64 bit machine. I couldn't find lxml egg for Python 2.7 version. So I am compiling it from sources. I am following instructions on this site

http://lxml.de/build.html

在静态链接部分下.我遇到错误了

under static linking section. I am getting error

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

有人可以帮助我吗?我尝试将路径设置为具有Microsoft Visual Studio. 我可以从命令行运行vcvarsall.bat..但是python出现了问题

Can any one help me with this? I tried setting the path to have Microsoft Visual Studio.. I can run vcvarsall.bat from the commandline.. but python is having problems

推荐答案

我敢打赌,您不是为此使用VS 2008的:)

I bet you're not using VS 2008 for this :)

def find_vcvarsall(version) :在distutils中的功能(猜测是什么,它寻找vcvarsall.bat)

There's def find_vcvarsall(version): function (guess what, it looks for vcvarsall.bat) in distutils with the following comment

首先,它尝试查找 注册表中VS 2008的productdir. 如果失败,则退回到 VS90COMNTOOLS环境变量.

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文件的原因.它不会检查通过PATH环境变量是否可以访问bat文件.

If you're not using VS 2008 then you have neither the registry key nor suitable environment variable and that's why distutils can't find vcvarsall.bat file. It does not check if the bat file is reachable through the PATH environment variable.

解决方案是定义VS90COMNTOOLS变量以指向Visual Studio的工具"目录.

The solution is to define VS90COMNTOOLS variable to point to Tools directory of Visual Studio.

话虽如此,请查看 11.4. distutils.msvccompiler — Python文档中的Microsoft编译器部分,其中指出

That being said take a look at 11.4. distutils.msvccompiler — Microsoft Compiler section in Python's docs which states

通常,扩展模块需要 用相同的编译器编译 用来编译Python.

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

Martin v.Loewis在标题为下载Visual Studio Express的电子邮件中python-list邮件列表上的2008年现在声明相同

Martin v. Loewis in the email titled Download Visual Studio Express 2008 now on python-list mailing list states the same

Python 2.6、2.7和3.1均已构建 该版本(即2008年)发布.因为 另一个悠久的传统,Python 扩展模块必须与 相同的编译器版本(更多 特别是CRT版本)作为Python 本身.所以要建立扩展模块 对于任何这些版本,您需要 拥有VS 2008或VS 2008的副本 快递.

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.

根据上述说明,如果要为Python 2.7构建lxml,则使用VS 2008,因此尽管设置VS90COMNTOOLS可以找到vcvarsall.bat文件,但不是 the strong>解决方案.

In the light of above statements you should use VS 2008 if you want to build lxml for Python 2.7 so although setting VS90COMNTOOLS takes care of finding vcvarsall.bat file it's not the solution.

话虽这么说:)人们确实尝试将旧的CRT与更新的编译器一起使用:
我可以将Visual Studio 2010的C ++编译器与Visual Studio 2008的C ++运行时库一起使用吗?
如何强制C ++编译器使用特定的CRT版本?
VS 2008-链接到较早的C运行时

That being said :) people do try to use older CRT with newer compiler:
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

我要感谢线程

I'd like to thank Kev Dwyer (for pointing out importance of version of VS which is used) and Stefan Behnel (for pointing me to distutils as a place dealing with compiler's configuration) in the thread Problem building lxml under Windows - error: Unable to find vcvarsall.bat on lxml mailing list. I'd like to also thank agronholm from freenode #distutils IRC channel for confirmation that distutils does contain code which looks for vcvarsall.bat file.

这篇关于在Windows上为Python 2.7构建lxml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆