无法导入Python扩展
我正在尝试学习 python 扩展,并且创建了简单的 noddy example 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.
那么,我是什么做错了吗?不可否认,我非常困惑。
I'm trying to learn python extensions, and I created the simple noddy example c file and setup.py.
python.exe setup.py build
gives me:
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
I then run python.exe setup.py install
, which gives me:
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
But then, in Idle,
>>> 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.
So, what am I doing wrong? Admittedly, I am horribly confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Visual Studio 2008 编译器构建模块。
VS8 是 Visual Studio 2005,使用该版本编译的模块与 Python 2.7 不兼容(同样适用于使用 Visual Studio 2010 编译的模块)。
Use the Visual Studio 2008 compiler to build the module.
VS8 is Visual Studio 2005 and the modules compiled with that version are incompatible with Python 2.7 (same applies to modules compiled with Visual Studio 2010 btw.).