IPython %% cython magic给出了ImportError:dlopen(long_file_name.so,2):找不到图像

时间:2013-01-19 01:41:28

标签: python-3.x ipython cython python-3.2

OS X,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, 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

这是我用来启动IPython笔记本会话的终端输出:

/Users/lab/.ipython/cython/_cython_magic_e9a2648cd85a2b3bce8e97b6bbc5f379.c:467:15: warning: 
      unused function
      '__pyx_f_46_cython_magic_e9a2648cd85a2b3bce8e97b6bbc5f379_fcy'
      [-Wunused-function]
static double __pyx_f_46_cython_magic_e9a2648cd85a2b3bce8e97b6bbc5f379_fcy(...
              ^
1 warning generated.

这对我有用,但不是上面的%% 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

任何人都知道这里的问题是什么?

0 个答案:

没有答案