draptik

mostly tech stuff

Pygments and Python

Frameworks like Octopress and Jekyll use the Python library Pygments for syntax highlighting.

Currenty (2013-05-23) Pygments does not work flawlessly with Python3 (see this post and this issue on pygment’s issue tracker).

This is a problem because many operating systems already provide Python3 as the default python installation.

To circumvent this issue, I found 2 different solutions:

  1. Rewire your system to always use python version X (i.e. 2.7) when python is called: See this post for an example solution.

  2. Sandbox Python installations.

Personally I prefer the approach of having a sandbox system. This way I don’t change the system’s default setting. Whenever I require a different Python version I can just switch it (this is similar to the Ruby Version Manager rvm).

This blog post explains some further details on how to install Octopress in Arch Linux. It comes down to installing python-virtualenvwrapper and configuring a new custom environment blog_env which uses Python 2.7:

Paraphrazing the original post:

To switch to the newly created blog_env, run workon blog_env. To exit a virtualenv, run deactivate.

Comments