2010-06-15 25 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