【问题标题】:cython setup.py gives .o instead of .dllcython setup.py 给出 .o 而不是 .dll
【发布时间】:2011-03-14 00:07:22
【问题描述】:

我是 cython 的新手,如果我在这里遗漏了一些明显的东西,请原谅我。我正在尝试构建 c 扩展以在 python 中使用以增强性能。我有具有一堆功能的 fc.py 模块,并尝试使用 dsutils 通过 cython 生成 .dll 并在 win64 上运行:

c:\python26\python c:\cythontest\setup.py build_ext --inplace

我在 C:\Python26\Lib\distutils 中有 dsutils.cfg。根据需要,disutils.cfg 具有以下配置设置:

[build]
compiler = mingw32

我的 startup.py 看起来像这样:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension('fc', [r'C:\cythonTest\fc.pyx'])]

setup(
  name = 'FC Extensions',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)

这是命令行输出的样子:

C:\python26\python C:\cythontest\setup.py build_ext --inplace
running build_ext
cythoning C:\cythonTest\fc.pyx to C:\cythonTest\fc.c
building 'FC' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\python26\include -Ic:\pytho
n26\PC -c C:\cythonTest\fc.c -o c:\cythontest\fc.o

我有用于目标/主机 amdwin64 类型构建的最新版本 mingw。我有最新版本的 cython for python26 for win64。 Cython 确实给了我一个没有错误的 fc.c,只有一些类型转换的警告,一旦我做对了,我就会处理。此外,它生成 fc.def 和 fc.o 文件,而不是提供 .dll。我没有错误。我在线程上发现它会根据需要自动创建 .so 或 .dll,但这并没有发生。

【问题讨论】:

  • 1.你看到*.pyd 文件了吗? 2. 从同一目录尝试,即更改 setup.py:Extension('fc', ['fc.pyx']) 并以python setup.py build_ext --inplace 运行它。 3.删除@​​987654329@中的空格也无妨:setup(name='FC', ..
  • @J.F.塞巴斯蒂安:谢谢 JFS,这行得通,我现在有了 .pyd。虽然我仍然有错误构建错误:ImportError: DLL load failed: %1 is not a valid Win32 application. 但我想这是来自使用 mingw,因为我 read 认为它在 win64 上不起作用。

标签: python dll cython win64


【解决方案1】:

最后,我能够为 win64 构建扩展。显然,如果您有 VC 2010 express,您可以调整 disuilts 以使用 msvc9compiler 编译模块。详情请见here。非常感谢 nukeitdotorg 的人提出这个问题,也感谢 J.F. Sebastian 的建议。

【讨论】:

  • 对于从 VS 2008 构建,在程序 x86 文件夹中的 VS 2008 中的某处找到 VCVARSALL.bat 的路径。然后在同一个 shell 或 .bat 中运行它,在 :> python setup.py build_ext --inplace 之前调用“-- path that you found --”。
【解决方案2】:

你有没有尝试用

编译它
python setup.py build --compiler=mingw32

?

【讨论】:

  • 是的,我编译了它,但它只适用于 32 位扩展。对于 64 位,mingw 不是 cython wiki 上推荐的 here 的好选择。
猜你喜欢
  • 2014-03-16
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 2013-10-08
  • 1970-01-01
  • 2016-12-23
  • 1970-01-01
相关资源
最近更新 更多