无法安装Kivy:Cython / GCC错误

19

我尝试按照官方网站的指示安装Kivy:

$ sudo apt-get install python-setuptools python-pygame python-opengl \
  python-gst0.10 python-enchant gstreamer0.10-plugins-good python-dev \
  build-essential libgl1-mesa-dev libgles2-mesa-dev python-pip

$ sudo pip install --upgrade cython

$ sudo easy_install kivy

这是我的输出结果:
Searching for kivy
Reading http://pypi.python.org/simple/kivy/
Best match: Kivy 1.4.1
Downloading http://pypi.python.org/packages/source/K/Kivy/Kivy-1.4.1.tar.gz#md5=94bba894269e4bdecc7881f256367e01
Processing Kivy-1.4.1.tar.gz
Running Kivy-1.4.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-MMi2Fv/Kivy-1.4.1/egg-dist-tmp-EcKbfC
[INFO   ] Kivy v1.4.1
Found GLES 2.0 headers at /usr/include/GLES2/gl2.h
Build configuration is:
 * use_opengl_es2  =  True
 * use_glew  =  False
 * use_opengl_debug  =  False
 * use_mesagl  =  False
Generate config.h
Generate config.pxi
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_f_4kivy_8graphics_14transformation_6Matrix_identity’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:2774:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_f_4kivy_8graphics_14transformation_6Matrix_inverse’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:2978:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:2980:13: error: incompatible types when assigning to type    ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_f_4kivy_8graphics_14transformation_6Matrix_multiply’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3364:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3366:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3368:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c: In function ‘__pyx_pf_4kivy_8graphics_14transformation_6Matrix_20__str__’:
/tmp/easy_install-MMi2Fv/Kivy-1.4.1/kivy/graphics/transformation.c:3674:13: error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’
 error: Setup script exited with error: command 'gcc' failed with exit status 1

在网上找不到答案后,我开始调查生成错误的文件:transformation.c、transformation.pyx和transformation.pyd。我也稍微了解了一下Cython。

首先,所有的错误都是同一类型的:

error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’

第一个错误在此处被引发:
__pyx_t_3 = __pyx_v_self->mat;
__pyx_t_3的类型是:
__pyx_t_4kivy_8graphics_14transformation_matrix_t

这个奇怪的名称是因为它是从 transformation.pxd 文件自动生成的:

ctypedef double matrix_t[16]

因此,type(__pyx_t_3)== type(matrix_t)== double *。
__pyx_v_self的类型是:
struct __pyx_obj_4kivy_8graphics_14transformation_Matrix *

这段内容是从transformation.pxd生成的:

ctypedef double matrix_t[16]

cdef class Matrix:
    cdef matrix_t mat
    ...

因此,type(__pyx_v_self->mat)== type(Matrix.mat)== type(matrix_t)== double *。
正如我们所看到的,在赋值语句的两侧:
__pyx_t_3 = __pyx_v_self->mat;

这里的数据类型是(double *)。

为什么会出现这个错误:

error: incompatible types when assigning to type ‘__pyx_t_4kivy_8graphics_14transformation_matrix_t’ from type ‘double *’

被提高了吗?

看起来编译器没有将matrix_t的类型识别为double *。

2个回答

16

刚遇到了同样的错误。使用Cython 0.17.1版本帮助了我:

sudo pip install Cython==0.17.1

如果你不仅想解决问题,还可以深入了解这两个版本之间发生了什么变化。 https://github.com/cython/cython/blob/master/CHANGES.rst#0172-2012-11-20 - 在这里,你可以找到相关的问题,但不幸的是我不是C/Cython的专家,快速查看主版本和0.17.1之间的差异并没有告诉我问题出在哪里,但如果你愿意,你可以自己调查一下。


哦,天啊,我简直不敢相信它可以工作!最初我使用的是较旧版本的Cython,然后我升级到了最新版本:0.17.2,我从未想过我应该得到一个更旧的版本才能让它工作。非常感谢! - orangesky
我遇到了这个错误:#error Do not use this file, it is the result of a failed Cython compilation error: command 'x86_64-linux-gnu-gcc' failed with exit status 1,但是现在已经解决了。谢谢!+1 - Charles Clayton

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接