我有一个使用YAML的Python程序。我尝试使用pip install yaml在新服务器上安装它,它返回以下信息:

$ sudo pip install yaml
Downloading/unpacking yaml
  Could not find any downloads that satisfy the requirement yaml
No distributions at all found for yaml
Storing complete log in /home/pa/.pip/pip.log

如何安装Python的yaml包?我运行的是Python 2.7。(操作系统:Debian Wheezy)


当前回答

有三个支持YAML的包。Syck (pip install Syck)实现了2002年的YAML 1.0规范;PyYAML (pip install PyYAML),它遵循2004年的YAML 1.1规范;和ruamel。它遵循最新的(2009年的yaml 1.2)规范。

您可以使用pip install ruamel安装YAML 1.2兼容包。yaml或者如果你正在运行现代版本的Debian/Ubuntu(或衍生版本),使用:

sudo apt-get install python-ruamel.yaml

其他回答

下面的命令将下载pyyaml,其中也包括yaml

pip install pyYaml

对我来说,安装开发版的利比亚就做到了。

yum install libyaml-devel         #centos
apt-get install libyaml-dev       # ubuntu

输入pip3 install yaml或像Connor那样输入pip3 install strictyaml

pip install PyYAML

如果没有找到或编译利比亚aml, PyYAML可以在Mavericks上没有它。

对于MacOS,这个答案是if

更新:现在安装是用pip完成的,对于许多用户来说,可能会有一个轮子(取决于你的Mac和所需的PyYaml版本)。在某些情况下,利比亚aml仍然需要构建C扩展(在mac上);这可以用:

brew install libyaml
python -m pip install pyyaml

过时的方法:

对于MacOSX (mavericks),以下工作:

brew install libyaml
sudo python -m easy_install pyyaml