没有值的return语句尝试在Python3.6中安装cgpolyEncode时

时间:2017-08-05 00:37:17

标签: python pip python-3.6 google-polyline

我的公司正在从Python 2.7迁移到Python 3.6,我正在尝试安装cGPolyEncode。但这根本不起作用,我得到了错误

 gpolyencode_py.cpp:187:69: error: ‘Py_InitModule3’ was not declared in this scope
                            "Google Maps Polyline encoding (C extension)");
                                                                         ^
    gpolyencode_py.cpp:190:9: error: return-statement with no value, in function returning ‘PyObject* {aka _object*}’ [-fpermissive]
             return;
             ^
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

每一次。一些快速谷歌搜索似乎表明模块本身需要重写,我没有资格做。我已经尝试了安装python3.6-dev libxml2-dev等基础知识,但问题仍然存在。是否有解决方法或安装方法而无需重建它?

1 个答案:

答案 0 :(得分:0)

在python2和python3之间的扩展名完全不同。但可以编写一个满足两者使用预处理器的文件。这是一个非常基本的C模块草图from my github

#include <Python.h>

static PyObject* _hello_world(PyObject* self) {
    return PyUnicode_FromString("hello world");
}

static struct PyMethodDef methods[] = {
    {"hello_world", (PyCFunction)_hello_world, METH_NOARGS},
    {NULL, NULL}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef module = {
    PyModuleDef_HEAD_INIT,
    "basic_c_module",
    NULL,
    -1,
    methods
};

PyMODINIT_FUNC PyInit_basic_c_module(void) {
    return PyModule_Create(&module);
}
#else
PyMODINIT_FUNC initbasic_c_module(void) {
    Py_InitModule3("basic_c_module", methods, NULL);
}
#endif

请注意,#else分支可能类似于当前模块的分支,您需要将其更新为更像#if PY_MAJOR_VERSION >= 3分支