Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

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

https://github.com/kamalgill/flask-appengine-template/blob/master/src/run.py

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top