Windows11下编译PyOpenGL-accelerate3.1.7报错的解决方法
修复PyOpenGL-accelerate 3.1.7在Python 3.13下的编译错误
可以修复,问题根源是PyOpenGL-accelerate 3.1.7的Cython代码依赖的Py_intptr_t类型在Python 3.13中已被移除(Python 3.13对C API做了清理,该类型替换为标准C的intptr_t),导致编译时类型识别失败。以下是具体修复方法:
方法一:修改源码重新编译安装
- 下载源码包:执行命令
会得到一个类似pip download pyopengl-accelerate==3.1.7PyOpenGL-accelerate-3.1.7.tar.gz的压缩包,解压到本地任意文件夹。 - 定位并修改报错文件:打开解压后文件夹中的
src\numpy_formathandler.pyx文件- 在文件开头添加Cython标准类型导入:
from cpython.stdint cimport intptr_t - 找到报错的第22行:
将cdef np.ndarray PyArray_Zeros(int nd, np.Py_intptr_t* dims, np.dtype, int fortran)np.Py_intptr_t替换为intptr_t,修改后变为:cdef np.ndarray PyArray_Zeros(int nd, intptr_t* dims, np.dtype, int fortran) - 检查文件中其他所有使用
Py_intptr_t的位置,全部替换为intptr_t
- 在文件开头添加Cython标准类型导入:
- 重新编译安装:进入解压后的文件夹,执行命令
pip install .
方法二:降级Python版本
如果不想修改源码,可以将Python版本降级到3.12及以下,这些版本仍保留Py_intptr_t类型,PyOpenGL-accelerate 3.1.7可以正常编译安装。
原编译错误信息:
Error compiling Cython file: ------------------------------------------------------------ ... cdef int PyArray_CheckScalar( object ) int NPY_ARRAY_CARRAY int NPY_ARRAY_FORCECAST int PyArray_ISCARRAY( np.ndarray instance ) int PyArray_ISCARRAY_RO( np.ndarray instance ) cdef np.ndarray PyArray_Zeros(int nd, np.Py_intptr_t* dims, np.dtype, int fortran) ^ ------------------------------------------------------------ src\numpy_formathandler.pyx:22:42: 'Py_intptr_t' is not a type identifier
内容的提问来源于stack exchange,提问作者Razzupaltuff
相关产品推荐
相关产品推荐

