【问题标题】:Error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’? when building a Cython extension错误:‘PyThreadState’ {aka ‘struct _ts’} 没有名为 ‘exc_type’ 的成员;你的意思是“curexc_type”吗?构建 Cython 扩展时
【发布时间】:2021-04-18 02:23:20
【问题描述】:

我在 Python 3.8 中收到以下错误,而在 Python 3.6 中我没有收到该错误。我怎样才能使它与 Python 3.8 一起工作?为了重现错误,请在此处关注:https://github.com/davidstutz/mesh-fusion/issues/7

[3645:3637 0:2090] 11:04:08 Tue Jan 12 [mona@goku:pts/0 +1] ~/mesh-fusion/libfusiongpu
$ python setup.py build_ext --inplace
Added OpenMP
running build_ext
skipping 'cyfusion.cpp' Cython extension (up-to-date)
building 'cyfusion' extension
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/mona/venv/tsdf/lib/python3.8/site-packages/numpy/core/include -I/home/mona/venv/tsdf/include -I/usr/include/python3.8 -c cyfusion.cpp -o build/temp.linux-x86_64-3.8/cyfusion.o -ffast-math -msse -msse2 -msse3 -msse4.2 -fopenmp
In file included from /home/mona/venv/tsdf/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1822,
                 from /home/mona/venv/tsdf/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/mona/venv/tsdf/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from cyfusion.cpp:531:
/home/mona/venv/tsdf/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~
cyfusion.cpp: In function ‘PyObject* PyInit_cyfusion()’:
cyfusion.cpp:22866:32: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22866 |   __pyx_type_8cyfusion_PyViews.tp_print = 0;
      |                                ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22866:32: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22866 |   __pyx_type_8cyfusion_PyViews.tp_print = 0;
      |                                ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22866:32: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22866 |   __pyx_type_8cyfusion_PyViews.tp_print = 0;
      |                                ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22871:33: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22871 |   __pyx_type_8cyfusion_PyVolume.tp_print = 0;
      |                                 ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22871:33: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22871 |   __pyx_type_8cyfusion_PyVolume.tp_print = 0;
      |                                 ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22871:33: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22871 |   __pyx_type_8cyfusion_PyVolume.tp_print = 0;
      |                                 ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22878:26: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22878 |   __pyx_type___pyx_array.tp_print = 0;
      |                          ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22878:26: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22878 |   __pyx_type___pyx_array.tp_print = 0;
      |                          ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22878:26: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22878 |   __pyx_type___pyx_array.tp_print = 0;
      |                          ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22883:32: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22883 |   __pyx_type___pyx_MemviewEnum.tp_print = 0;
      |                                ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22883:32: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22883 |   __pyx_type___pyx_MemviewEnum.tp_print = 0;
      |                                ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22883:32: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22883 |   __pyx_type___pyx_MemviewEnum.tp_print = 0;
      |                                ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22895:31: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22895 |   __pyx_type___pyx_memoryview.tp_print = 0;
      |                               ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22895:31: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22895 |   __pyx_type___pyx_memoryview.tp_print = 0;
      |                               ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22895:31: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22895 |   __pyx_type___pyx_memoryview.tp_print = 0;
      |                               ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22905:36: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22905 |   __pyx_type___pyx_memoryviewslice.tp_print = 0;
      |                                    ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22905:36: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22905 |   __pyx_type___pyx_memoryviewslice.tp_print = 0;
      |                                    ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp:22905:36: warning: ‘_typeobject::tp_print’ is deprecated [-Wdeprecated-declarations]
22905 |   __pyx_type___pyx_memoryviewslice.tp_print = 0;
      |                                    ^~~~~~~~
In file included from /usr/include/python3.8/object.h:746,
                 from /usr/include/python3.8/pytime.h:6,
                 from /usr/include/python3.8/Python.h:85,
                 from cyfusion.cpp:4:
/usr/include/python3.8/cpython/object.h:260:30: note: declared here
  260 |     Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      |                              ^~~~~~~~
cyfusion.cpp: In function ‘void __Pyx__ExceptionSave(PyThreadState*, PyObject**, PyObject**, PyObject**)’:
cyfusion.cpp:24028:21: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24028 |     *type = tstate->exc_type;
      |                     ^~~~~~~~
      |                     curexc_type
cyfusion.cpp:24029:22: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24029 |     *value = tstate->exc_value;
      |                      ^~~~~~~~~
      |                      curexc_value
cyfusion.cpp:24030:19: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24030 |     *tb = tstate->exc_traceback;
      |                   ^~~~~~~~~~~~~
      |                   curexc_traceback
cyfusion.cpp: In function ‘void __Pyx__ExceptionReset(PyThreadState*, PyObject*, PyObject*, PyObject*)’:
cyfusion.cpp:24037:24: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24037 |     tmp_type = tstate->exc_type;
      |                        ^~~~~~~~
      |                        curexc_type
cyfusion.cpp:24038:25: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24038 |     tmp_value = tstate->exc_value;
      |                         ^~~~~~~~~
      |                         curexc_value
cyfusion.cpp:24039:22: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24039 |     tmp_tb = tstate->exc_traceback;
      |                      ^~~~~~~~~~~~~
      |                      curexc_traceback
cyfusion.cpp:24040:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24040 |     tstate->exc_type = type;
      |             ^~~~~~~~
      |             curexc_type
cyfusion.cpp:24041:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24041 |     tstate->exc_value = value;
      |             ^~~~~~~~~
      |             curexc_value
cyfusion.cpp:24042:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24042 |     tstate->exc_traceback = tb;
      |             ^~~~~~~~~~~~~
      |             curexc_traceback
cyfusion.cpp: In function ‘int __Pyx__GetException(PyThreadState*, PyObject**, PyObject**, PyObject**)’:
cyfusion.cpp:24112:24: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24112 |     tmp_type = tstate->exc_type;
      |                        ^~~~~~~~
      |                        curexc_type
cyfusion.cpp:24113:25: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24113 |     tmp_value = tstate->exc_value;
      |                         ^~~~~~~~~
      |                         curexc_value
cyfusion.cpp:24114:22: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24114 |     tmp_tb = tstate->exc_traceback;
      |                      ^~~~~~~~~~~~~
      |                      curexc_traceback
cyfusion.cpp:24115:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24115 |     tstate->exc_type = local_type;
      |             ^~~~~~~~
      |             curexc_type
cyfusion.cpp:24116:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24116 |     tstate->exc_value = local_value;
      |             ^~~~~~~~~
      |             curexc_value
cyfusion.cpp:24117:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24117 |     tstate->exc_traceback = local_tb;
      |             ^~~~~~~~~~~~~
      |             curexc_traceback
cyfusion.cpp: In function ‘void __Pyx__ExceptionSwap(PyThreadState*, PyObject**, PyObject**, PyObject**)’:
cyfusion.cpp:24354:24: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24354 |     tmp_type = tstate->exc_type;
      |                        ^~~~~~~~
      |                        curexc_type
cyfusion.cpp:24355:25: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24355 |     tmp_value = tstate->exc_value;
      |                         ^~~~~~~~~
      |                         curexc_value
cyfusion.cpp:24356:22: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24356 |     tmp_tb = tstate->exc_traceback;
      |                      ^~~~~~~~~~~~~
      |                      curexc_traceback
cyfusion.cpp:24357:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_type’; did you mean ‘curexc_type’?
24357 |     tstate->exc_type = *type;
      |             ^~~~~~~~
      |             curexc_type
cyfusion.cpp:24358:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_value’; did you mean ‘curexc_value’?
24358 |     tstate->exc_value = *value;
      |             ^~~~~~~~~
      |             curexc_value
cyfusion.cpp:24359:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
24359 |     tstate->exc_traceback = *tb;
      |             ^~~~~~~~~~~~~
      |             curexc_traceback
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
19149/31772MB(tsdf) 


我有:

$ pip --version
pip 20.3.3 from /home/mona/venv/tsdf/lib/python3.8/site-packages/pip (python 3.8)
19149/31772MB(tsdf) 
[3645:3637 0:2092] 11:06:58 Tue Jan 12 [mona@goku:pts/0 +1] ~/mesh-fusion/libfusiongpu
$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cython
>>> cython.__version__
'0.29.21'
>>> quit()
19149/31772MB(tsdf) 
[3645:3637 0:2093] 11:07:14 Tue Jan 12 [mona@goku:pts/0 +1] ~/mesh-fusion/libfusiongpu
$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal
19365/31772MB(tsdf) 

【问题讨论】:

    标签: python c++ linux struct cython


    【解决方案1】:

    使用-f(或--force)强制重建/重新生成cythonized文件,即:

    python setup.py build_ext -i -f
    

    或者如果使用pip:

    pip install --global-option build --global-option --force .
    

    这可以粗略解释为:在安装之前运行build(包括build_ext),带有选项´--force`。


    目前的问题是,Cython 生成的 c/cpp 文件可能在未来与新的 Python 版本不兼容。

    一个例子是,Cython 0.27 不支持 Python3.8,因为当时 Python3.8 还不存在。因此,使用 Cython 0.27 创建的 c/cpp 文件(例如来自 git-repository 的 cyfusion.cpp)不会使用 Py3.8+-headers 构建。

    distutils使用时间戳来决定文件是否应该被重建/重新生成/recythonized,就它而言,Cython 生成的cyfusion.cpp-文件是最新的 - 因为cyfusion.pyx 不是t 在它的生成之后发生了变化。完全没有考虑整个不同的 Python/Cython 版本业务。

    因此,强制 distutils 重新构建所有内容可以解决 c/cpp 文件过时的问题。

    一般来说,我认为将 cython 生成的文件放入发行版/git 不是一个好主意,因为它可能/将成为未来的绊脚石,有一些例子:

    • ““tp_print 不是 _typeobject 的成员”-Python3.9+ 的错误(例如,post
    • 旧的 cython 版本没有属性 __reduce_cython__(例如这个 post

    另一个可能的解决方法是从 distribution/git-repository 中删除过时的(cython 生成的)cyfusion.cpp-file 并运行

    python setup.py build_ext -i
    

    之后。

    【讨论】:

    • 非常感谢您的回复。我按照你的建议做了,得到了这个错误pastebin.com/raw/fNuFwXSJ
    • @MonaJalal 您在就地构建时没有使用 -f/--force。您要么使用 pip 安装,要么就地构建。两者都做没有意义。
    【解决方案2】:

    我的问题解决了 改变

    python setup.py build_ext --inplace
    

    python setup.py build_ext --inplace -force
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-29
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      相关资源
      最近更新 更多