python - pip3 安装 PyYAML 失败。(python3.7,macOS High Sierra)

标签 python python-3.x

今天我用brew upgrade命令升级了python3.7。

我尝试使用 pip3 安装 PyYAML 包。

我遇到了这个错误并且不知道..

% pip3 install PyYAML

    checking if libyaml is linkable
    clang build/temp.macosx-10.13-x86_64-3.7/check_libyaml.o -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -lyaml -o build/temp.macosx-10.13-x86_64-3.7/check_libyaml
    building '_yaml' extension
    creating build/temp.macosx-10.13-x86_64-3.7/ext
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c ext/_yaml.c -o build/temp.macosx-10.13-x86_64-3.7/ext/_yaml.o
    In file included from ext/_yaml.c:271:
    ext/_yaml.h:10:9: warning: 'PyString_CheckExact' macro redefined [-Wmacro-redefined]
    #define PyString_CheckExact PyBytes_CheckExact
            ^
    ext/_yaml.c:139:11: note: previous definition is here
      #define PyString_CheckExact          PyUnicode_CheckExact
              ^
    ext/_yaml.c:1410:17: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
      __pyx_v_value = yaml_get_version_string();
                    ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
    ext/_yaml.c:2577:52: warning: incompatible pointer types passing 'int (void *, char *, size_t, size_t *)' (aka 'int (void *, char *, unsigned long, unsigned long *)') to parameter of type 'yaml_read_handler_t *' (aka 'int (*)(void *, unsigned char *, unsigned long, unsigned long *)') [-Wincompatible-pointer-types]
        yaml_parser_set_input((&__pyx_v_self->parser), __pyx_f_5_yaml_input_handler, ((void *)__pyx_v_self));
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/include/yaml.h:1370:30: note: passing argument to parameter 'handler' here 

....... 

最后

    /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
        PyObject *curexc_traceback;
                  ^
    51 warnings and 15 errors generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-exbgmayz/PyYAML/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-n11vy5s0/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-exbgmayz/PyYAML/

我试过解决这个问题,但还是不知道。

我该如何解决这个问题……?

最佳答案

PyYAML 的 C 扩展不能在 3.7 上编译,这就是错误消息的内容以及问题 126 的线程中的一些消息所指的内容。 PyYAML 安装程序中有一种机制应该测试 C 扩展是否可以编译,它主要检查 libyaml 是否可用。

我假设你升级到 3.7.0(而不是像你写的那样升级 Python3.7)所以我建议你降级到 3.6。虽然 PyYAML 的页面在 PyPI ,表示只支持3.4和3.5,3.6好像没问题。

如果你不能降级 Python,并且现在需要 3.7 的功能,你可以考虑使用 ruamel.yaml(免责声明:我是那个包的作者)。它本质上是 PyYAML 的超集,所以通常做

import ruamel.yaml as yaml

应该让你的程序工作。由于适用于 3.7 的 macOS wheels 在 PyPI 安装上可用,因此应该不会造成任何问题。

关于python - pip3 安装 PyYAML 失败。(python3.7,macOS High Sierra),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51165585/

相关文章:

python - Databricks Autoloader - 列转换 - 列不可迭代

python - 如何创建使用 `builds()` 的可配置自定义假设策略?

python - 尝试访问 pandas 数据框中新分配的列时出现 KeyError

python - 使用 Python 和 Flask 长时间运行的任务

python - `context` 中的 `multiprocessing.pool.Pool` 参数是什么意思?

python - SQL 到等效的 pandas

python - 在字符串 "BANANA"中使用 count 来使用 python 的 str.count() inbuild 函数查找 "ANA"作为子字符串时出现错误

python - 从 Python 模块内的 sys.path 中的路径读取图像

python-3.x - 如何计算直方图的标准偏差? (Python,Matplotlib)

python-3.x - Python 3 更新 MySQL 数据库表