错误点安装getch Python3.5

时间:2016-06-27 19:13:54

标签: python pip getch

我正在运行Fedora 24.我想在Python 3.5.2上导入getch模块(我认为已经安装了,但是当我运行python -V时,它说的是Python 2.7.11)

当我进入pip install getch时,我得到了这个:

Collecting getch
  Downloading getch-1.0.tar.gz
Installing collected packages: getch
  Running setup.py install for getch ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZsVfHE/getch/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-dOzMrO-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'getch' extension
    creating build
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c getchmodule.c -o build/temp.linux-x86_64-2.7/getchmodule.o
    getchmodule.c: En la función ‘getch_getche’:
    getchmodule.c:36:6: aviso: variable ‘ok’ sin usar [-Wunused-variable]
      int ok = PyArg_ParseTuple(args, "");
          ^~
    getchmodule.c: En la función ‘getch_getch’:
    getchmodule.c:43:6: aviso: variable ‘ok’ sin usar [-Wunused-variable]
      int ok = PyArg_ParseTuple(args, "");
          ^~
    getchmodule.c: En el nivel principal:
    getchmodule.c:54:15: error: la variable ‘getchmodule’ tiene inicializador pero de tipo de dato incompleto
     static struct PyModuleDef getchmodule = {
                   ^~~~~~~~~~~
    getchmodule.c:55:4: error: ‘PyModuleDef_HEAD_INIT’ no se declaró aquí (no en una función)
        PyModuleDef_HEAD_INIT,
        ^~~~~~~~~~~~~~~~~~~~~
    getchmodule.c:55:4: aviso: exceso de elementos en el inicializador de struct
    getchmodule.c:55:4: nota: (cerca de la inicialización de ‘getchmodule’)
    getchmodule.c:56:4: aviso: exceso de elementos en el inicializador de struct
        "getch",   /* name of module */
        ^~~~~~~
    getchmodule.c:56:4: nota: (cerca de la inicialización de ‘getchmodule’)
    getchmodule.c:58:4: aviso: exceso de elementos en el inicializador de struct
        -1,       /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
        ^
    getchmodule.c:58:4: nota: (cerca de la inicialización de ‘getchmodule’)
    getchmodule.c:59:4: aviso: exceso de elementos en el inicializador de struct
        GetchMethods
        ^~~~~~~~~~~~
    getchmodule.c:59:4: nota: (cerca de la inicialización de ‘getchmodule’)
    getchmodule.c: En la función ‘PyInit_getch’:
    getchmodule.c:64:9: aviso: declaración implícita de la función ‘PyModule_Create’ [-Wimplicit-function-declaration]
      return PyModule_Create(&getchmodule);
             ^~~~~~~~~~~~~~~
    getchmodule.c:64:9: aviso: ‘return’ con valor, en una función que devuelve void
      return PyModule_Create(&getchmodule);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    getchmodule.c:62:16: nota: se declara aquí
     PyMODINIT_FUNC PyInit_getch(void)
                    ^~~~~~~~~~~~
    getchmodule.c: En el nivel principal:
    getchmodule.c:54:27: error: no se conoce el tamaño de almacenamiento de ‘getchmodule’
     static struct PyModuleDef getchmodule = {
                               ^~~~~~~~~~~
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZsVfHE/getch/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-dOzMrO-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ZsVfHE/getch/

最后一行为红色。

那么,我怎样才能让它发挥作用呢?

谢谢

更新:好的,所以我设法将pip更新到最新版本,但现在我得到了下一个问题(似乎是一个进步):

好的,所以我设法将pip更新到最新版本,但现在我遇到了以下问题(似乎是一个进步):

`Collecting getch
  Using cached getch-1.0.tar.gz
Installing collected packages: getch
  Running setup.py install for getch: started
    Running setup.py install for getch: finished with status 'error'
    Complete output from command /usr/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pycharm-packaging1/getch/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-a0bmz59i-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'getch' extension
    creating build
    creating build/temp.linux-x86_64-3.5
    gcc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python3.5m -c getchmodule.c -o build/temp.linux-x86_64-3.5/getchmodule.o
    getchmodule.c:1:20: error fatal: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilación terminada.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------

Command "/usr/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pycharm-packaging1/getch/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-a0bmz59i-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pycharm-packaging1/getch/`

3 个答案:

答案 0 :(得分:1)

好的,这就是我修复它的方法:

sudo dnf install python3-devel

而不是:

sudo dnf install python-devel

经过数小时的研究,现在看起来很傻。

谢谢

答案 1 :(得分:1)

我正在使用Ubuntu,我遇到了同样的问题。我使用它修复了它:

pip install py-getch

答案 2 :(得分:0)

尝试一下

pip install --user py-getch