2010-11-18 66 views
1

我试图建立一个与Python的下PC \ example_nt源分布使用MS编译器

我复制example.c和setup.py的目录C例如建筑物上的窗户一个Python模块:\ mymod

当我运行C:\Python27\python.exe setup.py install我得到错误....

error: Unable to find vcvarsall.bat

我做了一些在distutils的挖四周,发现这是微软的Visual Studio,但只有我的9版本之后会有版本8.显然,它试图获得版本9,因为在C:\ Python27下编译了python。

我修改了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. 

我做错了什么? VS8不支持创建Python 2.7模块吗? 我该怎么办?

最终我需要为某些Windows C库构建绑定,以便我可以使用Python来扩展某些专有程序而不是C.我必须使用VS8来创建C扩展。那么这些离我而去。

请咨询。

感谢, 〜埃里克

+0

如果您必须使用VS8并希望使用Python 2.7,请使用VS8构建您自己的版本。不知道这可能会对您可能想要使用的任何其他第三方扩展有什么影响,除非您可以重建它们。 – martineau 2010-11-18 20:12:39

回答

1

一般来说,你必须建立使用VS的相同版本的蟒蛇与内置的Python模块。您有几种选择:

  1. 使用python2.6的,这点我觉得 VS8(或更早的版本,我敢肯定,有2.5和2.6之间的变化)
  2. 使用VS9。我认为你不能这样做,因为你使用的专有库是用VS8编译的。与python真的发生同样的问题。
  3. 使用ctypes创建绑定。这可能很难,而且很容易让你的程序崩溃。
  4. 使用VS8从源代码构建Python2.7。如果由于某种原因你不能使用Python2.6,那么这可能是最好的选择。

我会推荐选项1,如果它的工作。

+0

您可以从Microsoft [here](http://www.microsoft.com/downloads/en/details.aspx?FamilyId=F3FBB04E-92C2-4701-B4BA-92E26E408569&displaylang=en)下载VS 2008的免费版本。我相信这是用于编译Python 2.7的版本。不知道它是否可以在同一个系统上与另一个版本共存... – martineau 2010-11-18 20:04:43

+0

谢谢。我一定会给#1一个去。我已经尝试#4,我可以加载使用Visual Studio创建的示例pyd文件。当我去给调用库例程的模块添加另一个函数时,我变得无法在pyhon中导入包,并得到与之前相同的导入错误。 – 2010-11-19 12:37:45