Reputation: 903
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?
Upvotes: 1
Views: 4336
Reputation: 903
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')
Upvotes: 4