【发布时间】:2014-09-07 14:23:08
【问题描述】:
我想在我的 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
请注意,错误提示“安装成功”,但事实并非如此。
我不能import yaml
由于我的第一句话,我不是在寻找说“使用 apt-get”的答案。 我需要跨平台安装并作为 pip 依赖项工作我不只是想知道如何正确安装它。
如果这不可能,有没有我可以使用的库来替代?
【问题讨论】:
-
尝试在virtualenv中安装,
virtualenv pyenv && . pyenv/bin/activate && pip install pyyaml && python -c 'import yaml'可以吗? -
@spinus 适用于 python3 但不适用于 python2.7
-
对我来说也适用于 python2.7。很奇怪,我不知道出了什么问题。我知道你写的是新鲜的 ubuntu,但它真的那么新鲜吗?没有其他想法可能有什么问题。
-
@spinus 好的,我不确定。我刚刚在 AWS 中生成了一个新实例来测试它,而 pyyaml 显然是一个默认库。不知道为什么我第一次没有它。所以问题似乎是个体化的。 (可能会删除这个问题)
-
你是如何安装
pip的?它没有安装在全新的 Ubuntu 安装 AFAIK