2015-03-08 100 views
1

因此,當我嘗試使用以下setup.py腳本構建Cython擴展時出現此問題。使用distutils時發現vcvarsall.bat的問題

from distutils.core import setup 
from distutils.extension import Extension 
from Cython.Distutils import build_ext 
setup(
cmdclass = {'build_ext': build_ext}, 
ext_modules = [ 
Extension("program1",["program1.pyx"],),]) 

當我嘗試使用它建: python setup.py build我得到以下錯誤:

error: Unable to find vcvarsall.bat 

我使用微軟的Visual C++編譯程序包的Python 2.7。經過一番研究,其他一些SO問題讓我相信我的PATH變量沒有正確設置。

我設置如下:

VS90COMNTOOLS=C:\...\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\;

這是我的vcvarsall.bat文件的位置。這並沒有解決我的問題,因爲我仍然得到有關vcvarsall.bat的相同錯誤。 我知道已經有一堆關於這個特定錯誤的帖子,但我仍然沒有找到解決方案。

我發現this專門討論我的問題,但是我不明白以下步驟:

1) Enter MSVC for Python command prompt (how do I do this?) 
2) SET DISTUTILS_USE_SDK=1 
3) SET MSSdk=1 
4) python.exe setup.py ... 

最後:在討論進一步下跌史蒂夫提出與

更換

from distutils.core import setup 

from setuptools import setup 

這工作!但是現在我遇到了一個問題,每當我嘗試運行使用distutils setup而不是setuptools的東西時,它會引發相同的「無法找到vcvarsall.bat」問題。 例如,我嘗試使用IPython的魔法命令

%%cython_inline 

我已經在這幾天,現在,所有我想要的是正確的解決好這個問題,它已經非常令人沮喪。

最近修補了一個修補程序,該修補程序應該可以解決與查找vcvarsall.bat相關的問題。你可以看到here。我只是在裏面運行腳本/函數?它似乎沒有改變我distutils \ msvc9compiler.py文件中的任何東西。 我希望有人能在這裏指出我正確的方向。

回答

0

有關python bug跟蹤器here的進一步討論。這不是一個理想的解決方案,但馬克勞倫斯建議一個相當簡單的黑客行之有效。以下是建議:

My work around for this was to edit the distutils msvc9compiler.py file. 
I commented out the line vcvarsall = find_vcvarsall(version) in the function 
query_vcvarsall and hard coded vcvarsall = r'C:\Program Files\Microsoft 
Visual Studio 9.0\VC\vcvarsall.bat'. This assumes that you've got a copy of 
Visual C++!:) HTH. 

的msvc9compiler.py文件位於C:\ Python27 \ LIB \ distutils的(或者,如果你在不同的位置不是默認安裝Python的其他地方)。我做的唯一更改是將vcvarsall.bat文件指向我的特定MSVC編譯器。

在我的情況下,因爲我使用了Microsoft Visual C++編譯器包for Python 2。7編譯的Python,我改變變量如下:

vcvarsall = 
r'C:\Users\..\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python\9.0\vcvarsall.bat' #where .. is my user account name 
1

this message on the Python bug tracker

The correct solution to this issue now is to install the Microsoft supplied "Visual C++ Compiler for Python 2.7" package (available as a free download from MSDN). That has all the components needed to build 32 and 64-bit extensions. Your setup.py needs to use setuptools (as there is a setuptools extension to recognise this compiler package) but otherwise the process should be seamless.

+0

這是正確的。我的問題是當我使用仍然使用'from distutils.core import setup'的庫時。出於某種原因,我出現了錯誤。 – William 2015-06-17 15:15:21