Fabian Kostadinov

Problems Using Syntax Highlighting with Pygments on Windows

I wanted to turn on code syntax highlighting using rouge for my blog by adding the following line to my _config.yml file.

highlighter:   rouge

Whereas this worked perfectly on my local Windows machine, I ran into problems with Jekyll on GitHub. After searching for some time, I found this article from August 2014 where it stated:

Update: As of August 1, commiting a _config.yml that uses rouge now causes "Page build failure" on GitHub with a misleading error message like "The file _posts/2014-08-01-blah.md contains syntax errors." Before you commit & push, you must set highlighter: pygments in _config.yml, even if you don't care to install pygments locally.
It's now January 2015, and this was exactly the error message I received. So I figured there was/is a problem with rouge running on GitHub's Jekyll and decided to use pygments instead. My _config.yml file:

highlighter:   pygments

Whereas the change went through smoothly remotely on GitHub's Jekyll, I ran into problems locally. Whenever I tried to jekyll build my site, I received this error message:

Liquid Exception: No such file or directory - python2 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/pygments.rb-0.6.0/lib/pygments/mentos.py in _posts/2000-01-01-my-oldest-post.md

I did not know what this meant and it took me some hours to figure it out. The problem is that for any reason pygments is looking for a file python2.exe and cannot find it. I am using an Enthought Canopy python distribution, and what I do have is a file C:\Enthought-Canopy\User\python.exe as well as C:\Enthought-Canopy\User\Scripts\python.exe. First, I had to make sure that both directories containing these files were in my System PATH variable. Do not confuse with the User PATH variable. (Also don't forget to close and reopen the Windows command prompt afterwards, otherwise your changes are not effective.) Then I had to make a simple copy of python.exe and name it python2.exe. Alternatively, I could have created a hard link inside the same directory where python.exe exists and name it python2.exe.

cd C:\Enthought-Canopy\User
mklink /H python2.exe python.exe

cd C:\Enthought-Canopy\User\Scripts
mklink /H python2.exe python.exe
comments powered by Disqus