我写了一个简单的脚本。它集成了一个DE:
from scipy import integrate
def rhs(t, x):
return x
solver = integrate.ode(rhs)
solver.set_integrator('dopri5')
solver.set_initial_value(1.0, 0.0)
solver.integrate(0.2)
print solver.y
它的工作正确。但是如果我对它进行cythonize并从另一个python脚本加载,我会得到错误:
capi_return is NULL
Call-back cb_fcn_in___user__routines failed.
Traceback (most recent call last):
File "...\tmp\build\lib.win-amd64-2.7\test2.py", line 1, in <module>
import test
File "test.py", line 9, in init test (test.c:1113)
File "...\Anaconda\lib\site-packages\scipy\integrate\_ode.py", line 408, in integrate
self.f_params, self.jac_params)
File "...\Anaconda\lib\site-packages\scipy\integrate\_ode.py", line 1032, in run
tuple(self.call_args) + (f_params,)))
File "test.py", line 3, in test.rhs (test.c:748)
TypeError: rhs() takes exactly 2 positional arguments (1 given)
setup.py脚本包含:
from distutils.core import setup
from Cython.Build import cythonize
ext_modules = cythonize(['*.py'], exclude=['setup.py'])
setup(name='some_module', version='1.0', description='bla bla', ext_modules=ext_modules)
在第二个脚本中,我只需要调用
import test
P.S。我使用anaconda python-2.7 for windows7,x64。我有最新版本的scipy。我创建了testproject gitlab。