Search code examples
pythonpython-2.7pipgetch

pip install getch : clang error


I am trying to install getch via pip and I have a clang error :

python -m pip install getch
Collecting getch
  Using cached getch-1.0.tar.gz
Installing collected packages: getch
  Running setup.py install for getch ... error
    Complete output from command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/qm/gj1n93fd7rg8rgz1ldq19gm80000gn/T/pip-build-RYKX8n/getch/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/qm/gj1n93fd7rg8rgz1ldq19gm80000gn/T/pip-uEGRgA-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'getch' extension
    creating build
    creating build/temp.macosx-10.10-x86_64-2.7
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c getchmodule.c -o build/temp.macosx-10.10-x86_64-2.7/getchmodule.o
    getchmodule.c:36:6: warning: unused variable 'ok' [-Wunused-variable]
            int ok = PyArg_ParseTuple(args, "");
                ^
    getchmodule.c:43:6: warning: unused variable 'ok' [-Wunused-variable]
            int ok = PyArg_ParseTuple(args, "");
                ^
    getchmodule.c:55:4: error: use of undeclared identifier 'PyModuleDef_HEAD_INIT'
       PyModuleDef_HEAD_INIT,
       ^
    getchmodule.c:54:27: error: variable has incomplete type 'struct PyModuleDef'
    static struct PyModuleDef getchmodule = {
                              ^
    getchmodule.c:54:15: note: forward declaration of 'struct PyModuleDef'
    static struct PyModuleDef getchmodule = {
                  ^
    getchmodule.c:64:9: warning: implicit declaration of function 'PyModule_Create' is invalid in C99 [-Wimplicit-function-declaration]
            return PyModule_Create(&getchmodule);
                   ^
    3 warnings and 2 errors generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/qm/gj1n93fd7rg8rgz1ldq19gm80000gn/T/pip-build-RYKX8n/getch/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/qm/gj1n93fd7rg8rgz1ldq19gm80000gn/T/pip-uEGRgA-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/qm/gj1n93fd7rg8rgz1ldq19gm80000gn/T/pip-build-RYKX8n/getch/

I am using Mac so cannot use msvcrt.

Thank you for your help.


Solution

  • The installation is failing because it's looking for python3 headers. Looking at https://pypi.python.org/pypi/getch there are two source distributions listed, getch-1.0-python2.tar.gz and getch-1.0.tar.gz.

    For python 2 you need the former of those, but it looks like the latter one is being chosen (same thing happens for me). I'm not sure if/how pip is supposed to be able to know how to choose the correct one, but you can choose manually:

    copying the link,

    pip install https://pypi.python.org/packages/source/g/getch/getch-1.0-python2.tar.gz#md5=586ea0f1f16aa094ff6a30736ba03c50
    

    works for me