Take the 2-minute tour ×

This is my code:

from google.appengine.ext import db
import pygments
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

But I get:

import pygments
ImportError: No module named pygments
INFO     2012-07-20 07:05:44,386 dev_appserver.py:2952] "GET / HTTP/1.1" 500 -

What am I doing wrong?

Does Google App Engine not support pygments? I thought it did... Could someone please correct me?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

You can run Pygments because it's pure Python, but it's not included as a default library in GAE. Instead, you need to download the source and copy it into your project.

  1. Go to PyPi and download Pygments.

  2. Unzip it, then copy the source into the app engine folder for your project (probably best at the top-level).

  3. Then you can just do import pygments as usual. If you want to put it in a subdirectory (say mypackages), you have to change the import string, e.g. from mypackages import pygments.

share|improve this answer
THANK YOU SO MUCH, I would up vote, but I don't have enough reputation :\ –  areke Jul 20 '12 at 7:34
I got enough reputation :D –  areke Jul 20 '12 at 7:37
add comment

It supports it (since Pygments is pure Python), but it probably doesn't include it. Copy the module to one of the directories in sys.path.

share|improve this answer
Sorry, but how would I do this? –  areke Jul 20 '12 at 7:19
First you download it. Then you extract it. Then you copy it. –  Ignacio Vazquez-Abrams Jul 20 '12 at 7:20
add comment

Move 3rd parties to lib directory. Add this lines to your main file. Use pygments with import pygments

import os
import sys

sys.path.insert(1, os.path.join(os.path.abspath('.'), 'lib'))
import application


share|improve this answer
add comment

Your Answer


