几个月前,我写了this skeleton package,内容是使用NumPy和Cython将C库链接到Python。当我创建它时,编译工作正常,并且能够使用Python中的C代码。
但是,现在看来我的Python,Cython或NumPy版本已更改,无法再编译该软件包。我不知道的其中一个软件包中是否有API更改?找不到我的.pxd
头文件,并且在使用with nogil
时遇到许多编译错误,例如:
Error compiling Cython file:
------------------------------------------------------------
...
cdef long total
cdef long n = x.shape[0]
# If we want to use "nogil", we have to use "x.data", not "x".
with nogil:
total = sum_array(x.data, n)
^
------------------------------------------------------------
src/cython_wrapper.pyx:32:25: Coercion from Python not allowed without the GIL
但是重要的这些错误在早期版本的Cython(0.27.1)和NumPy(1.13.3)中不会发生。
以下是重现此内容的步骤:
virtualenv -p python3.6 old
cd old
source bin/activate
pip install cython==0.27.1 numpy==1.13.3
git clone https://github.com/GjjvdBurg/NumPy_C_Extension
cd NumPy_C_Extension
rm src/cython_wrapper.c
python setup.py build_ext -i
# Compilation proceeds without errors
virtualenv -p python3.6 new
cd new
source bin/activate
pip install cython==0.28.3 numpy==1.14.5
git clone https://github.com/GjjvdBurg/NumPy_C_Extension
cd NumPy_C_Extension
rm src/cython_wrapper.c
python setup.py build_ext -i
# Compilation fails
任何帮助将不胜感激!