pip 安装 getch Python3.5 时出错

Error pip installing getch Python3.5

我正在 运行ning 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/`

好的,我就是这样解决的:

sudo dnf install python3-devel

而不是:

sudo dnf install python-devel

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

谢谢

我正在使用 Ubuntu,我用同样的 issue.I 修复了它:

pip install py-getch

试试这个

pip install --user py-getch