2017-02-16 34 views
0

我最近從版本3.5的Winpython升級到使用python 3.6的相應版本。因此,我必須使用新的解釋器重新編譯我的C擴展。我的安裝腳本如下所示:Distutils在使用WinPython 3.6時不會調用「link.exe」,但是WinPython 3.5能夠正常工作

from distutils.core import setup, Extension 
import numpy.distutils.misc_util 

c_ext = Extension("heapoperations", ["heapoperations.c"]) 

setup(
    ext_modules=[c_ext], 
    include_dirs=numpy.distutils.misc_util.get_numpy_include_dirs(), 
) 

控制檯輸出使用Python 3.5的

running build_ext 
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils 
building 'heapoperations' extension 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I"C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\lib\site-packages\numpy\core\include" -I"C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\include" -I"C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" /Tcheapoperations.c /Fobuild\temp.win-amd64-3.5\Release\heapoperations.obj 
Found executable C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:"C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\libs" /LIBPATH:"C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\PCbuild\amd64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\um\x64" /EXPORT:PyInit_heapoperations build\temp.win-amd64-3.5\Release\heapoperations.obj /OUT:D:\MyProject\heapoperations.cp35-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.5\Release\heapoperations.cp35-win_amd64.lib 
Found executable C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe 

然而,當,當我運行與Python 3.6相同的腳本,我得到

running build_ext 
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils 
building 'heapoperations' extension 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I"C:\Program Files\WinPython-64bit-3.6.0.1Qt5\python-3.6.0.amd64\lib\site-packages\numpy\core\include" -I"C:\Program Files\WinPython-64bit-3.6.0.1Qt5\python-3.6.0.amd64\include" -I"C:\Program Files\WinPython-64bit-3.6.0.1Qt5\python-3.6.0.amd64\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\shared" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt" /Tcheapoperations.c /Fobuild\temp.win-amd64-3.6\Release\heapoperations.obj 
Found executable C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe 

那是,link.exe不叫。結果是我沒有得到允許我使用代碼的.pyd文件。

什麼能解釋行爲?我怎樣才能使一切工作在WinPython 3.6下?

我在Windows 10 64位下使用64位WinPython。

+0

可能不是答案,而是重新嘗試將python.exe旁邊的文件重命名爲python._pth,如python_nomore._pth – stonebig

+0

@stonebig我已經完成了。它對這個問題沒有影響。我知道你對我以前的問題的答案http://stackoverflow.com/questions/42263962/modulenotfounderror-python-3-6-does-not-find-modules-while-python-3-5-does/42266369? noredirect = 1#comment71720852_42266369 – Samufi

+0

好吧,另一個愚蠢的想法是,以前用python-3.5對象編譯過的邊界效應......也許試着改變你的文件的名字,以確保系統中沒有「先前」對象? – stonebig

回答

0

我做了一個嘗試從http://dan.iel.fm/posts/python-c-extensions/ (從https://gist.github.com/douglas-larocca/099bf7460d853abb7c17 _chi2.c)

結果:

C:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\notebooks>python setup.py build_ext --inplace 
running build_ext 
No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils 
building '_chi2' extension 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\lib\site-packages\numpy\core\include -IC:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\include -IC:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\include -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\8.1\include\shared" -I"C:\Program Files (x86)\Windows Kits\8.1\include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tc_chi2.c /Fobuild\temp.win-amd64-3.6\Release\_chi2.obj 
Found executable C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\lib\site-packages\numpy\core\include -IC:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\include -IC:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\include -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\8.1\include\shared" -I"C:\Program Files (x86)\Windows Kits\8.1\include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcchi2.c /Fobuild\temp.win-amd64-3.6\Release\chi2.obj 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\libs /LIBPATH:C:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\python-3.6.0.amd64\PCbuild\amd64 /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" /EXPORT:PyInit__chi2 build\temp.win-amd64-3.6\Release\_chi2.obj build\temp.win-amd64-3.6\Release\chi2.obj /OUT:C:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\notebooks\_chi2.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\_chi2.cp36-win_amd64.lib 
Found executable C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe 

C:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\notebooks> 

結果的測試:

PS C:\WinPython\basedir36\buildQt5\winpython-64bit-3.6.x.2\notebooks> python 
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import _chi2; print (_chi2.chi2(2.0, 1.0, [-1.0, 4.2, 30.6], [-1.5, 8.0, 63.0], [1.0, 1.5, 0.6])) 
2.8988888888888766 
相關問題