python - 无法导入 python 扩展

标签 python windows python-c-extension

我正在尝试学习 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.

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

最佳答案

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

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

关于python - 无法导入 python 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4950547/

相关文章:

Python 内存不足(使用后缀树)

python - pandas - python 导出为 xls 而不是 xlsx - ExcelWriter

c++ - ctypes:初始化数组数组并传递给 C 函数

java - 删除 java 构建路径中的 .jar 或从 E : to F: 更改路径

python - 使用 C API 创建自定义类对象的 numpy 数组

python - 如何内省(introspection) Cython C 扩展模块中定义的函数

Python 在 O(n) 解决方案中检查 Anagram

python - 我可以使用 python 're' 来解析复杂的人名吗?

c# - UPX最好的压缩方式是什么

c# - 将 .NET C# 程序集成到已编译(非托管)C++ 程序中(无需执行单独的 .exe 文件)