cython编译但没有生成pyd文件

cython compiles but no pyd files are generated

我试过运行一个python代码,说myfile.py(也试过重命名为myfile.pyx)如下:

import pyximport
pyximport.install(setup_args={"script_args":["--compiler=mingw32"]},      
    reload_support=True)

import myfile
myfile.mycode()

我正在使用 PyCharm。代码似乎 运行 没有任何错误,甚至在 PyCharm 内的 Python 控制台上给了我正确的结果。

但是没有生成 pyd(或 pxd)文件。我怎么知道我的代码 (myfile.mycode()) 运行 是通过 Cython 还是通过常规 Python?

我正在使用 Python 3.4,Cython 0.21.2。

谢谢

pyximport 生成一个不在工作目录中的临时 pyd 文件。您可能想要构建一个看起来像这样的 setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension('myfile',
                         sources=['myfile.pyx'],
                         language='c++',
                        )]
setup(
name = 'myfile',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)

您可以使用以下方式编译:

python setup.py build_ext -i clean