本文翻译自:How do I install the yaml package for Python?
I have a Python program that uses YAML. 我有一个使用YAML的Python程序。 I attempted to install it on a new server using pip install yaml
and it returns the following: 我尝试使用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
How do I install the yaml package for Python? 如何安装适用于Python的yaml软件包? I'm running Python 2.7. 我正在运行Python 2.7。 (OS: Debian Wheezy) (作业系统:Debian Wheezy)
#1楼
参考:https://stackoom.com/question/xq62/如何安装适用于Python的yaml软件包
#2楼
pip install pyyaml
If you don't have pip, run easy_install pip
to install pip, which is the go-to package installer - Why use pip over easy_install? 如果没有pip,请运行easy_install pip
来安装pip,这是必备的软件包安装程序- 为什么在easy_install上使用pip? . 。 If you prefer to stick with easy_install, then easy_install pyyaml
如果您喜欢坚持使用easy_install,则easy_install pyyaml
#3楼
You could try the search feature in pip, 您可以尝试使用点子搜索功能,
$ pip search yaml
which looks for packages in PyPI with yaml in the short description. 它在简短说明中使用yaml在PyPI中查找软件包。 That reveals various packages, including PyYaml, yamltools, and PySyck, among others (Note that PySyck docs recommend using PyYaml, since syck is out of date). 这揭示了各种软件包,包括PyYaml,yamltools和PySyck等(请注意, PySyck文档建议使用PyYaml,因为syck已过时)。 Now you know a specific package name, you can install it: 现在您知道了特定的软件包名称,可以安装它:
$ pip install pyyaml
If you want to install python yaml system-wide in linux, you can also use a package manager, like aptitude
or yum
: 如果要在linux系统范围内安装python yaml,还可以使用软件包管理器,例如aptitude
或yum
:
$ sudo apt-get install python-yaml
$ sudo yum install python-yaml
#4楼
Update: Nowadays installing is done with pip, but libyaml is still required to build the C extension (on mac): 更新:如今,安装已通过pip完成,但仍需要libyaml来构建C扩展(在Mac上):
brew install libyaml
python -m pip install pyyaml
Outdated method : 过时的方法 :
For MacOSX (mavericks), the following seems to work: 对于MacOSX(小牛),以下方法似乎有效:
brew install libyaml
sudo python -m easy_install pyyaml
#5楼
pip install PyYAML
如果找不到libyaml或编译的PyYAML可以在Mavericks上不使用它。
#6楼
There are three YAML capable packages. 有三个支持YAML的软件包。 Syck ( pip install syck
) which implements the YAML 1.0 specification from 2002; Syck( pip install syck
),从2002年开始实施YAML 1.0规范; PyYAML ( pip install pyyaml
) which follows the YAML 1.1 specification from 2004; PyYAML( pip install pyyaml
),遵循2004年的YAML 1.1规范; and ruamel.yaml which follows the latest (YAML 1.2, from 2009) specification. ruamel.yaml遵循最新的规范(从2009年开始使用YAML 1.2)。
You can install the YAML 1.2 compatible package with pip install ruamel.yaml
or if you are running a modern version of Debian/Ubuntu (or derivative) with: 您可以使用pip install ruamel.yaml
安装YAML 1.2兼容软件包,或者如果您运行的是Debian / Ubuntu(或衍生版本)的现代版本,请执行以下操作:
sudo apt-get install python-ruamel.yaml