使用pip /添加PyYaml作为pip依赖项安装pyyaml

Nic*_*ich 18 python yaml pip

我想在我的pip项目中使用PyYaml,但是在使用它作为依赖项时遇到了麻烦.主要问题是pip中的PyYaml不是跨平台安装.

如何使用pip安装pyyaml以使其正常工作.注意,在当前新的Ubuntu安装上,运行时出现以下错误pip install pyyaml

Installing collected packages: pyyaml
  Running setup.py install for pyyaml
    checking if libyaml is compilable
    gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC -I/usr/include/python3.2mu -c build/temp.linux-x86_64-3.2/check_libyaml.c -o build/temp.linux-x86_64-3.2/check_libyaml.o
    build/temp.linux-x86_64-3.2/check_libyaml.c:2:18: fatal error: yaml.h: No such file or directory
    compilation terminated.

    libyaml is not found or a compiler error: forcing --without-libyaml
    (if libyaml is installed correctly, you may need to
     specify the option --include-dirs or uncomment and
     modify the parameter include_dirs in setup.cfg)

Successfully installed pyyaml
Run Code Online (Sandbox Code Playgroud)

请注意,错误显示"已成功安装",但事实并非如此.我不能import yaml

由于我的第一句话,我不是在寻找说"使用apt-get"的答案.我需要安装是跨平台的,并作为一个pip依赖工作我不是简单地想知道如何正确安装它.

如果这是不可能的,我可以使用任何替换库吗?

Sal*_*lem 25

你需要一些额外的包来构建它.

首先,您需要卸载pyyaml,否则稍后会抱怨它已经安装

pip uninstall pyyaml
Run Code Online (Sandbox Code Playgroud)

然后安装以下包:

sudo apt-get install libyaml-dev libpython2.7-dev
Run Code Online (Sandbox Code Playgroud)

最后再安装一次

pip install pyyaml
Run Code Online (Sandbox Code Playgroud)

  • 不,pyyaml不需要libyaml-dev.如果安装pyyaml可以使用它作为更有效的实现,但它不是必需的.对我来说,``pip install pyyaml``没有外部的东西,同样的错误工作正常. (3认同)