Python 3.x IPython%%cython magic提供导入错误:dlopen(长\u文件\u name.so,2):找不到图像
OSX,10.7。我已经阅读了cython教程中的前几个cython示例,到目前为止,所有教程示例对我来说都是正确的 然而,当我尝试做费尔南多在加拿大Pycon上的科学和Python演示时(在播放位置37:42),我得到了一个奇怪的错误。代码是:Python 3.x IPython%%cython magic提供导入错误:dlopen(长\u文件\u name.so,2):找不到图像,python-3.x,ipython,cython,python-3.2,Python 3.x,Ipython,Cython,Python 3.2,OSX,10.7。我已经阅读了cython教程中的前几个cython示例,到目前为止,所有教程示例对我来说都是正确的 然而,当我尝试做费尔南多在加拿大Pycon上的科学和Python演示时(在播放位置37:42),我得到了一个奇怪的错误。代码是: %load_ext cythonmagic %%cython cdef double fcy(double x) except? -2: return x**2-x def integrate_fcy(double a, double b,
%load_ext cythonmagic
%%cython
cdef double fcy(double x) except? -2:
return x**2-x
def integrate_fcy(double a, double b, int N):
cdef int i
cdef double s, dx
s = 0; dx = (b-a)/N
for i in range(N):
s += fcy(a+i*dx)
return s * dx
笔记本输出:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-72-e327d909d703> in <module>()
----> 1 get_ipython()._run_cached_cell_magic('cython', '')
/usr/local/lib/python3.2/site-packages/IPython/core/interactiveshell.py in _run_cached_cell_magic(self, magic_name, line)
2513 cell = self._current_cell_magic_body
2514 self._current_cell_magic_body = None
-> 2515 return self.run_cell_magic(magic_name, line, cell)
2516
2517 def run_cell(self, raw_cell, store_history=False, silent=False):
/usr/local/lib/python3.2/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2092 magic_arg_s = self.var_expand(line, stack_depth)
2093 with self.builtin_trap:
-> 2094 result = fn(line, cell)
2095 return result
2096
/usr/local/lib/python3.2/site-packages/IPython/extensions/cythonmagic.py in cython(self, line, cell)
/usr/local/lib/python3.2/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
190 # but it's overkill for just that one bit of state.
191 def magic_deco(arg):
--> 192 call = lambda f, *a, **k: f(*a, **k)
193
194 if isinstance(arg, collections.Callable):
/usr/local/lib/python3.2/site-packages/IPython/extensions/cythonmagic.py in cython(self, line, cell)
187 self._code_cache[key] = module_name
188
--> 189 module = imp.load_dynamic(module_name, module_path)
190 self._import_all(module)
191
ImportError: dlopen(/Users/lab/.ipython/cython/_cython_magic_0e71fc3338606be06aed17a605e60bbd.cpython-32m.so, 2): image not found
这对我来说还行,但不是上面的%%cython魔法:
a=10
b=20
%%cython_inline
return a+b
Compiling /Users/lab/Library/Caches/cython/inline/_cython_inline_074486d5a226d2c163f10589ac495ca2.pyx because it changed.
Cythonizing /Users/lab/Library/Caches/cython/inline/_cython_inline_074486d5a226d2c163f10589ac495ca2.pyx
Out[52]: 30
有人知道这里的问题是什么吗?如果你能用Cython在Python 3.2中加载一些OK的东西,你能用IPython吗?很高兴。谢谢你的建议。对于其他看到同样情况的人来说,问题在于:
a=10
b=20
%%cython_inline
return a+b
Compiling /Users/lab/Library/Caches/cython/inline/_cython_inline_074486d5a226d2c163f10589ac495ca2.pyx because it changed.
Cythonizing /Users/lab/Library/Caches/cython/inline/_cython_inline_074486d5a226d2c163f10589ac495ca2.pyx
Out[52]: 30