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

pip3 install PyYAML failed.(python3.7, macOS High Sierra)

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

我试着用pip3安装pyyaml包。

我有这个错误,不知道……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
% 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

.......

最后

1
2
3
4
5
6
7
8
9
10
11
    /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('

'
, '
'
);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/

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

  • https://github.com/yaml/pyyaml/issues/126
  • 如何安装python的yaml包?

如何解决此问题….


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的超集,所以通常

1
import ruamel.yaml as yaml

应该让你的程序正常工作。由于3.7版的MacOS车轮在Pypi安装中可用,因此不应导致任何问题。


python3.7打破了pyyaml的构建。使用Python 3.6。