How do I install the yaml package for Python?

2019-01-10 02:16发布

I have a Python program that uses YAML. I attempted to install it on a new server using pip install yaml and it returns the following:

$ 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? I'm running Python 2.7. (OS: Debian Wheezy)

8条回答
看我几分像从前
2楼-- · 2019-01-10 02:32

"There should be one -- and preferably only one -- obvious way to do it." So let me add another one. This one is more like "install from sources" for Debian/Ubuntu, from https://github.com/yaml/pyyaml

Install the libYAML and it's headers:

sudo apt-get install libyaml-dev

Download the pyyaml sources:

wget http://pyyaml.org/download/pyyaml/PyYAML-3.13.tar.gz

Install from sources, (don't forget to activate your venv):

. your/env/bin/activate
tar xzf PyYAML-3.13.tar.gz
cd PyYAML-3.13.tar.gz
(env)$ python setup.py install
(env)$ python setup.py test 
查看更多
干净又极端
3楼-- · 2019-01-10 02:35

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?. If you prefer to stick with easy_install, then easy_install pyyaml

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-10 02:42

You could try the search feature in pip,

$ pip search yaml

which looks for packages in PyPI with yaml in the short description. That reveals various packages, including PyYaml, yamltools, and PySyck, among others (Note that PySyck docs recommend using PyYaml, since syck is out of date). 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:

$ sudo apt-get install python-yaml
$ sudo yum install python-yaml
查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-10 02:42

For me, installing development version of libyaml did it.

yum install libyaml-devel         #centos
apt-get install libyaml-dev       # ubuntu
查看更多
老娘就宠你
6楼-- · 2019-01-10 02:43

There are three YAML capable packages. Syck (pip install syck) which implements the YAML 1.0 specification from 2002; PyYAML (pip install pyyaml) which follows the YAML 1.1 specification from 2004; and ruamel.yaml which follows the latest (YAML 1.2) specification.

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:

sudo apt-get install python-ruamel.yaml
查看更多
叛逆
7楼-- · 2019-01-10 02:45
pip install PyYAML

If libyaml is not found or compiled PyYAML can do without it on Mavericks.

查看更多
登录 后发表回答