cython编译但未生成pyd文件 [英] cython compiles but no pyd files are generated

查看:512
本文介绍了cython编译但未生成pyd文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行python代码,例如 myfile.py (还尝试将其重命名为 myfile.pyx )如下:

I tried to run a python code, say myfile.py (also tried to rename it as myfile.pyx) as follows:

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

import myfile
myfile.mycode()

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

I am using PyCharm. The code seems to have run fine without any error and even gave me correct results on the Python Console within PyCharm.

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

However no pyd (or pxd) files were generated. How can I know if my code (myfile.mycode()) ran via Cython or via regular Python?

我正在使用Python 3.4,Cython 0.21.2。

I am using Python 3.4, Cython 0.21.2.

谢谢

推荐答案

使用pyximport时,将生成一个临时 pyd 文件,该文件不在工作目录中。您可能想构建一个 setup.py ,它看起来像:

When using pyximport it will generate a temporary pyd file which is not in the working directory. You probably want to build a setup.py which will look something like:

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

您可以使用以下命令进行编译:

which you can compile using:

python setup.py build_ext -i clean

这篇关于cython编译但未生成pyd文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆