使用 Cython 界面为时间试验的几何级数运行迭代循环。
编译时出现错误(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
最佳答案
我知道这个问题很老,但我认为这可能对其他人有所帮助。
我在 Windows 上为一个旧的 Py2.7 项目遇到了这个问题。
如果在 Windows 上并使用 Py2.7,请检查您是否安装了适用于 Python 的 MS Visual Studio C++ 编译器 (download link)。不确定 Py3 需要进行哪些更改。
对于您的 anaconda 环境,找到 Lib\distutils
目录并创建一个 distutils.cfg
文件(如果不存在,否则只需根据需要修改当前文件)。
您希望构建配置如下所示。
[build]<br/>
compiler=msvc
如果在 Linux 上,确保你有必要的 devel
可用的包,例如
Ubuntu:apt-get install python-devel
关于python - 在 Jupyter iPython 中运行 Cython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35656604/