1

我正在尝试学习 python 扩展,并创建了简单的noddy 示例c 文件和 setup.py。

python.exe setup.py build 给我:

running build
running build_ext
building 'noddy' 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 /Tcnoddy.c /Fobuild\temp.win32-2.7\Release\noddy.obj
noddy.c
creating build\lib.win32-2.7
C:\Program Files\Microsoft Visual Studio 8\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\python27\libs /LIBPATH:C:\python27\PCbuild /EXPORT:initnoddy build\temp.win32-2.7\Release\noddy.obj /OUT:build\lib.win32-2.7\noddy.pyd /IMPLIB:build\temp.win32-2.7\Release\noddy.lib /MANIFESTFILE:build\temp.win32-2.7\Release\noddy.pyd.manifest
Creating library build\temp.win32-2.7\Release\noddy.lib and object build\temp.win32-2.7\Release\noddy.exp
C:\Program Files\Microsoft Visual Studio 8\VC\BIN\mt.exe -nologo -manifest build\temp.win32-2.7\Release\noddy.pyd.manifest -outputresource:build\lib.win32-2.7\noddy.pyd;2

然后我运行python.exe setup.py install,这给了我:

running install
running build
running build_ext
running install_lib
copying build\lib.win32-2.7\noddy.pyd -> C:\python27\Lib\site-packages
running install_egg_info
Writing C:\python27\Lib\site-packages\noddy-1.0-py2.7.egg-info

但是,在空闲时,

>>> import noddy

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import noddy
ImportError: DLL load failed: The specified module could not be found.

那么,我做错了什么?诚然,我非常困惑。

4

1 回答 1

3

使用 Visual Studio 2008 编译器构建模块。

VS8 是 Visual Studio 2005,使用该版本编译的模块与 Python 2.7 不兼容(同样适用于使用 Visual Studio 2010 编译的模块)。

于 2011-02-09T22:37:08.317 回答