[英]Running Cython in Jupyter iPython
使用Cython接口為時間試驗運行迭代循環以獲得幾何級數。
編譯時出錯(shift-enter):CompileError:命令'gcc'失敗,退出狀態為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
我能夠使用Anaconda3無錯誤地重現這個:
%load_ext Cython
%%cython -a
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
例:
geo_prog_cython(0.5, 5)
1.96875
代碼似乎很好。 這一定是您設置的問題。
我知道這個問題已經很老了,但我認為這可能有助於其他人。
我在Windows上遇到了一個舊的Py2.7項目的問題。
如果在Windows上,並使用Py2.7檢查您是否安裝了用於Python的MS Visual Studio C ++編譯器( 下載鏈接 )。 不確定Py3需要做哪些更改。
對於您的anaconda環境,找到Lib\\distutils
目錄並創建一個distutils.cfg
文件(如果尚未存在,否則只需根據需要修改當前文件)。
您希望構建配置如下所示。
[build]
compiler=msvc
如果在linux上,請確保您有必要的devel
包,例如
Ubuntu: apt-get install python-devel
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.