使用python3错误构建cython时出错:在此范围内未声明“ PyString_AsString” [英] Error building cython with python3 error: 'PyString_AsString' was not declared in this scope

查看:455
本文介绍了使用python3错误构建cython时出错:在此范围内未声明“ PyString_AsString”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python 3中使用cython编译ac扩展时遇到麻烦。它可以在python 2.7中编译并正常工作,但是在python 3.4.3中,使用3.4(anaconda发行版)进行构建时出现以下错误: b
$ b

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

问题是我的其他大多数模块都是为3.4编写的,因此2.7并不是真正的选择。

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?

推荐答案

因此,事实证明python 3中对python字符串的处理方式不同,所以对我来说,简单的解决方案是将 PyString_AsString(s)替换为 s.encode('UTF-8')

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')

这篇关于使用python3错误构建cython时出错:在此范围内未声明“ PyString_AsString”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆