在Jupyter iPython中运行Cython [英] Running Cython in Jupyter iPython

查看:192
本文介绍了在Jupyter iPython中运行Cython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Cython界面为时间试用运行迭代循环以实现几何级数.

Running an iterative loop for a geometric progression for a time trial, using the Cython interface.

获取编译错误(shift-enter):CompileError:命令'gcc'失败,退出状态为1

Get an error on compile (shift-enter): CompileError: command 'gcc' failed with exit status 1

%load_ext Cython

%%cython
def geo_prog_cython(double alpha, int n):
    cdef double current = 1.0
    cdef double sum = current
    cdef int i
    for i in range(n):
        current = current * alpha
        sum = sum + current
    return sum

错误:

//anaconda/lib/python3.5/distutils/command/build_ext.py in build_extension(self, ext)
    530                                          debug=self.debug,
    531                                          extra_postargs=extra_args,
--> 532                                          depends=ext.depends)
    533 
    534         # XXX outdated variable, kept here in case third-part code

推荐答案

我知道这个问题已经很久了,但我认为这可能会对其他人有所帮助.

I know this question is quite old but I thought this may help some others.

我在Windows上遇到了一个旧的Py2.7项目的问题.

I ran into this issue on Windows for an old Py2.7 project.

如果在Windows上并使用Py2.7,请检查是否已安装用于Python的MS Visual Studio C ++编译器(

If on Windows, and using Py2.7 check that you have the MS Visual Studio C++ compiler for Python installed (download link). Not sure what changes are necessary for Py3.

对于您的anaconda环境,请找到Lib\distutils目录并创建一个distutils.cfg文件(如果尚未存在,请根据需要修改当前文件).

For your anaconda environment, locate the Lib\distutils directory and create a distutils.cfg file (if not already there, otherwise just modify the current file as necessary).

您希望构建配置如下所示.

You want the build config to look like below.

[build]
compiler=msvc

[build]
compiler=msvc

如果在Linux上,请确保您有必要的devel软件包可用,例如

If on linux, make sure you have the necessary devel packages available, e.g.

Ubuntu:apt-get install python-devel

这篇关于在Jupyter iPython中运行Cython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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