pip install getch:clang 错误

pip install getch : clang error

我正在尝试通过 pip 安装 getch,但出现 clang 错误:

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/

我正在使用 Mac 所以不能使用 msvcrt。

感谢您的帮助。

安装失败,因为它正在寻找 python3 headers。查看 https://pypi.python.org/pypi/getch,列出了两个源代码分布,getch-1.0-python2.tar.gzgetch-1.0.tar.gz

对于 python 2,您需要前者,但看起来正在选择后者(我也遇到了同样的事情)。我不确定if/how pip应该可以知道如何选择正确的,但你可以手动选择:

复制 link、

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

适合我