我有一个c++函数:
double* hiho() {
double *res = new double[10];
return res;
}
与
from numpy.ctypeslib import ndpointer
mylib.hiho.restype = ndpointer(dtype=ctypes.c_double, shape=(10,))
当调用该函数时,我得到以下错误:
ValueError: '<P' is not a valid PEP 3118 buffer format string
我使用Python 3.6.2
我做错了什么?
发布于 2020-02-11 14:09:54
我已经将numpy更新到版本1.18.1。现在,这个方法运行得很好:
from numpy.ctypeslib import ndpointer
mylib.hiho.restype = ndpointer(dtype=ctypes.c_double, shape=(10,))
要简单地更新numpy:
pip install numpy --upgrade
供您参考:
在numpy 1.15.4中,我与您的示例Mark With *double或*int出现了相同的错误。
我在MacOS上的编译代码行:
g++ -c -fPIC -std=c++17 test.cpp -o test.o
g++ -dynamiclib -undefined suppress -flat_namespace test.o -o test.dylib
或
g++ -c test.cpp -o test.o
g++ -dynamiclib -undefined suppress -flat_namespace test.o -o test.dylib
错误:
ValueError: '<P' is not a valid PEP 3118 buffer format string
https://stackoverflow.com/questions/51655753
复制相似问题