Error building cython with python3 error: 'PyString_AsString' was not declared in this scope

筅森魡賤 提交于 2019-12-23 02:55:17

问题


I am having trouble compiling a c extension using cython in python 3. It compiles and works fine with python 2.7, but in python 3.4.3 I get the following error when building with 3.4 (anaconda distribution):

python setup.py build_ext --inplace
running build_ext
building 'module' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Iincludes -I/home/user/anaconda/include/python3.4m -c module.cpp -o build/temp.linux-x86_64-3.4/module.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
rawdata.cpp: In function ‘int __pyx_pf_7rawdata_13RawDataReader___cinit__(__pyx_obj_7rawdata_RawDataReader*, PyObject*, int, int)’:
rawdata.cpp:852: error: ‘PyString_AsString’ was not declared in this scope 
error: command 'gcc' failed with exit status 1

The problem is that most of my other modules are written for 3.4 so staying with 2.7 is not really an option.

Any idea on how to get around this?


回答1:


So it turns out that python strings are handled differently in python 3 so the simple solution for me was to replace PyString_AsString(s) with s.encode('UTF-8')



来源:https://stackoverflow.com/questions/29109685/error-building-cython-with-python3-error-pystring-asstring-was-not-declared-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!