首页 > 解决方案 > Mojave 上的 pyenv 在安装 3.5.6、3.6.7 时抛出未声明的标识符“CLOCK_REALTIME”和其他错误

问题描述

我正在尝试在 macOS Mojave 上安装各种版本的 python3 10.14.2 Beta (18C52a)

3.6.7 失败:

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.6.7.tar.xz...
-> https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz
Installing Python-3.6.7...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14.2 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/db/pjnyydt54kl3_snfwpvlsxf40000gp/T/python-build.20181204115752.83999
Results logged to /var/folders/db/pjnyydt54kl3_snfwpvlsxf40000gp/T/python-build.20181204115752.83999.log

Last 10 log lines:
./Include/pytime.h:200:52: warning: declaration of 'struct tm' will not be visible outside of this function [-Wvisibility]
PyAPI_FUNC(int) _PyTime_localtime(time_t t, struct tm *tm);
                                                   ^
./Include/pytime.h:204:49: warning: declaration of 'struct tm' will not be visible outside of this function [-Wvisibility]
PyAPI_FUNC(int) _PyTime_gmtime(time_t t, struct tm *tm);
                                                ^
2 warnings generated.
2 warnings generated.
2 warnings generated.
2 warnings generated.

3.5.6 失败:

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.5.6.tar.xz...
-> https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tar.xz
Installing Python-3.5.6...
python-build: use readline from homebrew

BUILD FAILED (OS X 10.14.2 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/db/pjnyydt54kl3_snfwpvlsxf40000gp/T/python-build.20181204115931.92145
Results logged to /var/folders/db/pjnyydt54kl3_snfwpvlsxf40000gp/T/python-build.20181204115931.92145.log

Last 10 log lines:
Python/pytime.c:508:13: warning: implicit declaration of function 'clock_getres' is invalid in C99 [-Wimplicit-function-declaration]
        if (clock_getres(CLOCK_REALTIME, &res) == 0)
            ^
Python/pytime.c:508:13: warning: this function declaration is not a prototype [-Wstrict-prototypes]
Python/pytime.c:508:26: error: use of undeclared identifier 'CLOCK_REALTIME'
        if (clock_getres(CLOCK_REALTIME, &res) == 0)
                         ^
4 warnings and 2 errors generated.
make: *** [Python/pytime.o] Error 1
make: *** Waiting for unfinished jobs....

我试过了,通过brew

  1. 重新安装所有pyenv, python, python3, xz, readline, openssl(根据这个答案
  2. 我已经尝试安装和重新安装 macOS 开发者工具
  3. 我试过sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /(根据 pyenv 文档)
  4. 我在一个新的 Mojave running 版本上尝试了这个10.14.1 (18B75),我遇到了同样的问题。

哦,该死的,我正在使用 Fish。我将不得不看看这是否是鱼特定的问题(更新:不,它不是鱼,它发生在标准中/bin/sh

标签: pythonpython-3.xmacosmacos-mojavepyenv

解决方案


我不知道这是否是问题所在,但是当我尝试安装多个 pip 包时遇到了类似的错误,这些 pip 包的构建步骤依赖于time.h. 问题是我有一个流浪者,里面缺乏必要的出口/usr/local/include。如果您(错误)使用 brew,您可能会在/usr/local/*. 我建议获取详细的输出,找到产生错误的确切构建命令,查看每个-I标志,然后递归搜索time.h. 我敢打赌,其中一个是你想要摆脱的遗物。


推荐阅读