我正在尝试在PC \ example_nt下构建python源代码分发附带的示例
我将example.c和setup.py复制到目录C:\ mymod
当我运行C:\Python27\python.exe setup.py install
时出现错误。...
error: Unable to find vcvarsall.bat
我在distutils中进行了一些挖掘,发现它正在使用Microsoft Visual Studio版本9,但我只有版本8。显然,由于C:\ Python27下的python是用什么编译的,因此它试图获取版本9。
我修改了setup.py,并将以下内容放在最顶部。
from distutils import msvc9compiler
msvc9compiler.VERSION = 8.0
完成此操作后,我可以进行编译并获得以下内容。...
C:\mymod>C:\Python27\python.exe setup.py install
running install
running build
running build_ext
building 'example' extension
creating build
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
C:\Program Files\Microsoft Visual Studio 8\VC\BIN\cl.exe /c /nologo /Ox /MD /W3
/GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcexample.c /Fobuild\temp.
win32-2.7\Release\example.obj
example.c
creating build\lib.win32-2.7
C:\Program Files\Microsoft Visual Studio 8\VC\BIN\link.exe /DLL /nologo /INCREME
NTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild /EXPORT:initexamp
le build\temp.win32-2.7\Release\example.obj /OUT:build\lib.win32-2.7\example.pyd
/IMPLIB:build\temp.win32-2.7\Release\example.lib /MANIFESTFILE:build\temp.win32
-2.7\Release\example.pyd.manifest
Creating library build\temp.win32-2.7\Release\example.lib and object build\te
mp.win32-2.7\Release\example.exp
C:\Program Files\Microsoft Visual Studio 8\VC\BIN\mt.exe -nologo -manifest build
\temp.win32-2.7\Release\example.pyd.manifest -outputresource:build\lib.win32-2.7
\example.pyd;2
running install_lib
copying build\lib.win32-2.7\example.pyd -> C:\Python27\Lib\site-packages
running install_egg_info
Removing C:\Python27\Lib\site-packages\example-1.0-py2.7.egg-info
Writing C:\Python27\Lib\site-packages\example-1.0-py2.7.egg-info
现在当我运行C:\ Python27 \ python.exe并尝试import example
时,我得到以下信息...
ImportError: DLL load failed: The specified module could not be found.
我做错什么了吗?创建Python 2.7模块不支持VS8吗?我该怎么办?
最终,我需要为某些Windows C库构建绑定,以便可以使用Python扩展某些专有程序而不是C。我必须使用VS8来创建C扩展。那那把我留在哪里?
请咨询。
谢谢,〜Eric
通常来说,您必须使用与构建python相同的VS版本来构建python模块。您有几种选择:
如果可行,我会建议选项1。