0

我正在尝试运行用 python 制作的程序,但出现错误:

“ImportError:没有模块名称多边形”

我正在使用 ubuntu、python 2.7 和 EPD 7.3-1。

如何下载 Python 模块 Polygon 的包和 C 扩展?

我试过:

sudo apt-get install python-polygon
sudo apt-get install python-polygon2

什么也没发生。

我从作者的页面下载了 zip 文件:“Polygon2-2.0.6.rar”。之后,我将 Polygon2-2.0.6.rar 提取到 Polygon2-2.0.6,然后我转到该文件夹​​并运行 python setup.py install

给我:

jose@jose-Satellite-L845:~/Descargas/Polygon2-2.0.6$ python setup.py install

Using NumPy extension!
running install
running build
running build_py
running build_ext
building 'Polygon.cPolygon' extension

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DDEFAULT_STYLE=STYLE_LIST -DWITH_NUMPY=1 -Isrc -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c src/gpc.c -o build/temp.linux-x86_64-2.7/src/gpc.o

src/gpc.c: In function ‘gpc_read_polygon’:
src/gpc.c:1037:9: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

fscanf(fp, "%d", &(p->num_contours)); ^

src/gpc.c:1044:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

 fscanf(fp, "%d", &(p->contour[c].num_vertices));
       ^

src/gpc.c:1047:13: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

   fscanf(fp, "%d", &(p->hole[c]));
         ^
src/gpc.c:1054:13: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

   fscanf(fp, "%lf %lf", &(p->contour[c].vertex[v].x),
         ^

src/gpc.c: In function ‘gpc_polygon_clip’:

src/gpc.c:1471:31: warning: ‘dy’ may be used uninitialized in this function [-Wmaybe-uninitialized]

   build_intersection_table(&it, aet, dy);
                           ^

src/gpc.c:1460:12: warning: ‘yt’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     if (edge->top.y == yt)
        ^

src/gpc.c:1328:20: warning: ‘tr’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     vclass= tr + (tl << 1) + (br << 2) + (bl << 3);
                ^

src/gpc.c:1133:34: warning: ‘tl’ may be used uninitialized in this function [-Wmaybe-uninitialized]

int vclass, bl, br, tl, tr; ^

src/gpc.c:1133:30: warning: ‘br’ may be used uninitialized in this function [-Wmaybe-uninitialized]

int vclass, bl, br, tl, tr; ^

src/gpc.c:1133:26: warning: ‘bl’ may be used uninitialized in this function [-Wmaybe-uninitialized]

int vclass, bl, br, tl, tr; ^

src/gpc.c:1330:12: warning: ‘contributing’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     if (contributing)
        ^

src/gpc.c: In function ‘gpc_tristrip_clip’:

src/gpc.c:2131:31: warning: ‘dy’ may be used uninitialized in this function [-Wmaybe-uninitialized]

   build_intersection_table(&it, aet, dy);
                           ^

src/gpc.c:2120:12: warning: ‘yt’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     if (edge->top.y == yt)
        ^

src/gpc.c:1981:20: warning: ‘tr’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     vclass= tr + (tl << 1) + (br << 2) + (bl << 3);
                ^

src/gpc.c:1794:34: warning: ‘tl’ may be used uninitialized in this function [-Wmaybe-uninitialized]

int vclass, bl, br, tl, tr; ^

src/gpc.c:1794:30: warning: ‘br’ may be used uninitialized in this function [-Wmaybe-uninitialized]

int vclass, bl, br, tl, tr; ^

src/gpc.c:1794:26: warning: ‘bl’ may be used uninitialized in this function [-Wmaybe-uninitialized]

int vclass, bl, br, tl, tr; ^

src/gpc.c:1983:12: warning: ‘contributing’ may be used uninitialized in this function [-Wmaybe-uninitialized]

     if (contributing)
        ^

src/gpc.c:2062:16: warning: ‘cft’ may be used uninitialized in this function [-Wmaybe-uninitialized]

         if (cft == LED)
            ^

src/gpc.c:2064:26: warning: ‘cf’ may be used uninitialized in this function [-Wmaybe-uninitialized]

           if (cf->bot.y == yb)
                      ^

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DDEFAULT_STYLE=STYLE_LIST -DWITH_NUMPY=1 -Isrc -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c src/cPolygon.c -o build/temp.linux-x86_64-2.7/src/cPolygon.o

src/cPolygon.c:4:20: fatal error: Python.h: No existe el archivo o el directorio

    #include <Python.h>
                ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

请帮忙。提前致谢。

4

1 回答 1

1

下载 zip 文件,解压缩文件,cd 到文件夹中,运行python setup.py buildpython setup.py install.

编辑:根据您的回答,您需要安装 python-dev 。

命令是:sudo apt-get install python-dev

于 2013-10-28T20:58:51.383 回答