MacOS 上 Python 3.7 中的底图构建错误——来自 Cython?

Build error for Basemap in Python 3.7 on MacOS -- coming from Cython?

我一直在拼命尝试为 Python 3.7 重新安装 Basemap,在执行 sudo python3 setup.py build 时,我继续 运行 进入这个长长的错误列表:

_proj.c:7421:21: error: no member named 'exc_type' in 'struct _ts'
    *type = tstate->exc_type;
            ~~~~~~  ^
_proj.c:7422:22: error: no member named 'exc_value' in 'struct _ts'; did you mean 'curexc_value'?
    *value = tstate->exc_value;
                     ^~~~~~~~~
                     curexc_value
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:237:15: note: 'curexc_value' declared here
    PyObject *curexc_value;
              ^
_proj.c:7423:19: error: no member named 'exc_traceback' in 'struct _ts'; did you mean 'curexc_traceback'?
    *tb = tstate->exc_traceback;
                  ^~~~~~~~~~~~~
                  curexc_traceback
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
    PyObject *curexc_traceback;
              ^
_proj.c:7435:24: error: no member named 'exc_type' in 'struct _ts'
    tmp_type = tstate->exc_type;
               ~~~~~~  ^
_proj.c:7436:25: error: no member named 'exc_value' in 'struct _ts'; did you mean 'curexc_value'?
    tmp_value = tstate->exc_value;
                        ^~~~~~~~~
                        curexc_value
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:237:15: note: 'curexc_value' declared here
    PyObject *curexc_value;
              ^
_proj.c:7437:22: error: no member named 'exc_traceback' in 'struct _ts'; did you mean 'curexc_traceback'?
    tmp_tb = tstate->exc_traceback;
                     ^~~~~~~~~~~~~
                     curexc_traceback
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
    PyObject *curexc_traceback;
              ^
_proj.c:7438:13: error: no member named 'exc_type' in 'struct _ts'
    tstate->exc_type = type;
    ~~~~~~  ^
_proj.c:7439:13: error: no member named 'exc_value' in 'struct _ts'; did you mean 'curexc_value'?
    tstate->exc_value = value;
            ^~~~~~~~~
            curexc_value
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:237:15: note: 'curexc_value' declared here
    PyObject *curexc_value;
              ^
_proj.c:7440:13: error: no member named 'exc_traceback' in 'struct _ts'; did you mean 'curexc_traceback'?
    tstate->exc_traceback = tb;
            ^~~~~~~~~~~~~
            curexc_traceback
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
    PyObject *curexc_traceback;
              ^
_proj.c:7483:24: error: no member named 'exc_type' in 'struct _ts'
    tmp_type = tstate->exc_type;
               ~~~~~~  ^
_proj.c:7484:25: error: no member named 'exc_value' in 'struct _ts'; did you mean 'curexc_value'?
    tmp_value = tstate->exc_value;
                        ^~~~~~~~~
                        curexc_value
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:237:15: note: 'curexc_value' declared here
    PyObject *curexc_value;
              ^
_proj.c:7485:22: error: no member named 'exc_traceback' in 'struct _ts'; did you mean 'curexc_traceback'?
    tmp_tb = tstate->exc_traceback;
                     ^~~~~~~~~~~~~
                     curexc_traceback
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
    PyObject *curexc_traceback;
              ^
_proj.c:7486:13: error: no member named 'exc_type' in 'struct _ts'
    tstate->exc_type = local_type;
    ~~~~~~  ^
_proj.c:7487:13: error: no member named 'exc_value' in 'struct _ts'; did you mean 'curexc_value'?
    tstate->exc_value = local_value;
            ^~~~~~~~~
            curexc_value
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:237:15: note: 'curexc_value' declared here
    PyObject *curexc_value;
              ^
_proj.c:7488:13: error: no member named 'exc_traceback' in 'struct _ts'; did you mean 'curexc_traceback'?
    tstate->exc_traceback = local_tb;
            ^~~~~~~~~~~~~
            curexc_traceback
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
    PyObject *curexc_traceback;
              ^
15 warnings and 15 errors generated.
error: command 'clang' failed with exit status 1

在这一点上,我很确定问题出在 Cython 上,因为调用了错误版本的 Cython,正如此处指出的:https://github.com/matplotlib/basemap/issues/414,但我不知道如何 "regenerate the C sources"。我试过 cythonize --force src/_geoslib.pyx 但我发现 cythonize 不存在。 关于可能发生的事情以及如何解决它的任何想法?

注意:底图在我 sudo python setup.py build 时工作正常,它调用 Python 2.7 而不是 3.7。

我遇到了同样的问题。正如 DavidW 在评论中所说的那样,我首先需要安装 cython。 pyshp 也丢失了:

pip3 install cython
pip3 install pyshp

但是swig也没有安装。所以我需要:

brew install swig

然后我不得不通过 pip 安装底图:

 pip3 install -U git+https://github.com/matplotlib/basemap.git

注意:我已经手动安装了 geos-3.3.3,所以我不确定通过 github 的 pip 安装是否也会安装

我在尝试使用 mac catalina 在 python 3.8.12 上安装 kmc2 时遇到了同样的问题。我通过 git 克隆 kmc2 存储库并在安装安装之前手动对 pyx 文件进行 cythonize 修复。