Search code examples
pythonpipgetch

Error pip installing getch Python3.5


I'm running Fedora 24. I want to import the getch module on Python 3.5.2 (which I think is already installed, however when I run python -V, it says Python 2.7.11)

When I enter pip install getch I get this:

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/

Last line is in red.

So, how can I make it work?

Thank you


Update: Ok, so I managed to update pip to the latest version, but now I get the next problem (seems like a progress):

Ok, so I managed to get pip updated to the latest version, but now I get the following problem (seems like a progress):

`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/`

Solution

  • Ok, so this is how I fixed it:

    sudo dnf install python3-devel
    

    Instead of:

    sudo dnf install python-devel
    

    After hours of research, now it seems so silly.

    Thank you