How do I install the yaml package for Python?


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)

Asked By: harperville



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

Answered By: harperville

You could try the search the feature on (via a browser) and look 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
Answered By: Bonlenfum

This answers if for MacOS

Update: Nowadays installing is done with pip, and for many users a wheel may be available (depending on your Mac and required version of PyYaml). In some cases libyaml is still required to build the C extension (on mac); this can be done with:

brew install libyaml
python -m pip install pyyaml

Outdated method:

For MacOSX (mavericks), the following works:

brew install libyaml
sudo python -m easy_install pyyaml
Answered By: tutuDajuju
pip install PyYAML

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

Answered By: bbaassssiiee

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, from 2009) 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
Answered By: Anthon

Debian-based systems:

$ sudo aptitude install python-yaml

or newer for python3

$ sudo aptitude install python3-yaml

Answered By: hbadger

For me, installing development version of libyaml did it.

yum install libyaml-devel         #centos
apt-get install libyaml-dev       # ubuntu
Answered By: Mayank Jaiswal

“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

Install the libYAML and it’s headers:

sudo apt-get install libyaml-dev

Download the pyyaml sources:


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 install
(env)$ python test 
Answered By: Sergey Belash

following command will download pyyaml, which also includes yaml

pip install pyYaml
Answered By: Ankit Shukla

Consider using strictyaml instead

If you have the luxury of creating the yaml file yourself, or if you don’t require any of these features of regular yaml, I recommend using strictyaml instead of the standard pyyaml package.

In short, default yaml has some serious flaws in terms of security, interface, and predictability. strictyaml is a subset of the yaml spec that does not have those issues (and is better documented).

You can read more about the problems with regular yaml here

OPINION: strictyaml should be the default implementation of yaml and the old yaml spec should be obsoleted.

Answered By: Connor

Type in pip3 install yaml or like Connor pip3 install strictyaml

Answered By: Gurshan Sekhon

️ in a virtual environment or using Python 2

pip install pyyaml

️ for python 3 (could also be pip3.10 depending on your version)

pip3 install pyyaml

️ if you get permissions error

sudo pip3 install pyyaml

️ if you don’t have pip in your PATH environment variable

python -m pip install pyyaml

️ for python 3 (could also be pip3.10 depending on your version)

python3 -m pip install pyyaml

️ for Anaconda

conda install -c conda-forge pyyaml

Answered By: hailuodev

If you’re running Python scripts with sudo and facing module import errors, it’s likely due to sudo not preserving the PYTHONPATH from your Conda environment. To fix this, explicitly set the PYTHONPATH to include your Conda environment’s site-packages directory before running your script with sudo. Here’s how:

export PYTHONPATH="/home/enviornment_name/miniconda3/envs/car/lib/python2.7/site-packages:$PYTHONPATH"
Answered By: Md Ruman Islam

The other answers didn’t work for me because I didn’t have root privileges on the machine I was working on. A colleague suggested the below command which worked. This installs the pyyaml package for the current logged in user.

python3 -m pip install --user PyYAML
Answered By: rahuljain1311
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.