Python and YAML on Ubuntu 14.04

warning

This post is more than 5 years old. While math doesn't age, code and operating systems do. Please use the code/ideas with caution and expect some issues due to the age of the content. I am keeping these posts up for archival purposes because I still find them useful for reference, even when they are out of date!

In this post I will cover installing PyYAML using Python 2.7. I've previously covered my approach to Python package installation using pip in this post: Install Python packages on Ubuntu 14.04 . You can read there to get a sense of my approach.

First we install the YAML libraries for Ubuntu (apparently this is not needed and PyYAML can be installed as pure Python, so skip this step if you like):

$ sudo apt-get install libyaml-dev

Next, we install PyYAML for Python support:

$ pip install --user PyYAML

If you installed libyaml-dev above, some compiling occurs, otherwise a pure Python version is installed. In either case, we can see the version of PyYAML installed using:

$ pip show PyYAML
---
Name: PyYAML
Version: 3.11
Location: /home/cstrelioff/.local/lib/python2.7/site-packages
Requires:

This package will both parse and render YAML as demonstrated in the {% sbUrl refs["PyYAML documentation"] %} PyYAML documentation -- I show a yaml.load below:

>>> import yaml
>>>
>>> print yaml.load("""
... field1: value1
... field2: value2
... a list:
... - list item 1
... - list item 2
... """
)
{'field2': 'value2', 'a list': ['list item 1', 'list item 2'], 'field1':
'value1'}

That's it for now, checkout the PyYAML site for more.