python - pip 安装 getch : clang error

标签 python python-2.7 pip getch

我正在尝试通过 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 header 。看着https://pypi.python.org/pypi/getch列出了两个源分发版,getch-1.0-python2.tar.gzgetch-1.0.tar.gz

对于 python 2,您需要前者,但看起来正在选择后者(同样的事情发生在我身上)。我不确定 pip 是否/如何知道如何选择正确的,但您可以手动选择:

复制链接,

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

对我有用

关于python - pip 安装 getch : clang error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36714728/

相关文章:

python - eclipse : "Python not configured"

python - 使用python进行数据提取及其求和

python - pip(或 setuptools、distribute 等)可以列出每个已安装软件包使用的许可证吗?

python - Virtualenv 在 OS X Yosemite 上失败并出现 OSError

python - 如何解决此功能,使其对程序中的所有选项都有效?

python - 将 bytearray 转换为 array.array ('B' )

python - Python 2.7 的 Jupyter 安装失败

python - tensorflow 值错误: Batch length of predictions should be same

python - Django、PIP 和 Virtualenv

python - 阻止 Pandas 对列进行排序