Python 使用 pip 安装 pyyaml/将 PyYaml 添加为 pip 依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24791251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install pyyaml using pip/Add PyYaml as pip dependency
提问by Nick Humrich
I want to use PyYaml in my pip project, but am having trouble using it as a dependency. Mainly the problem is thet PyYaml in pip is not a cross platform install.
我想在我的 pip 项目中使用 PyYaml,但无法将其用作依赖项。主要问题是 pip 中的 PyYaml 不是跨平台安装。
How do I install pyyaml using pip so that it works. Note, on a current fresh Ubuntu install I get the following error when running pip install 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
Note that the error says "successfully installed" but it is not.
I can not import yaml
请注意,错误显示“已成功安装”,但事实并非如此。我不能import yaml
I am not looking for answers that say "use apt-get" due to my very first sentence. I need the install to be cross platform and work as a pip dependencyI am not simply wondering on how to install it correctly.
由于我的第一句话,我不是在寻找说“使用 apt-get”的答案。我需要跨平台安装并作为 pip 依赖项工作我不仅仅是想知道如何正确安装它。
If this is not possible, is there any library I can use in replacement?
如果这是不可能的,我可以使用任何库来代替吗?
回答by Salem
You will need some extra packages to build it.
您将需要一些额外的包来构建它。
First of all you need to uninstall pyyaml
, or it will complain later that it is already installed
首先你需要卸载pyyaml
,否则它会抱怨它已经安装了
pip uninstall pyyaml
Then install the following packages:
然后安装以下软件包:
sudo apt-get install libyaml-dev libpython2.7-dev
Finally install it again
最后重新安装
pip install pyyaml
回答by Kevin D'Cruz
Virtual Environment Setting
虚拟环境设置
Python version: 3.6.3
Operating system: Windows, 64 Bits
Keras was not installing because of pyyaml setting not meeting up for python 3.6.
I already had Anaconda installed in a different virtualenv with keras working fine (pyyaml module installed). I just used conda install pyyaml instead of pip and it got installed, thereby using pip install keras
to install the keras library in my new virtual environment.
Keras 没有安装,因为 pyyaml 设置不符合 python 3.6。我已经将 Anaconda 安装在不同的 virtualenv 中,keras 工作正常(安装了 pyyaml 模块)。我只是使用 conda install pyyaml 而不是 pip 并安装了它,从而pip install keras
用于在我的新虚拟环境中安装 keras 库。
if you have anaconda installed already, try using
如果您已经安装了 anaconda,请尝试使用
conda install yaml
conda 安装 yaml
and see if it works. It worked for me!
看看它是否有效。它对我有用!