Pygments for Google App Engine Python Doesn't Work
-
22-06-2021 - |
Pregunta
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?
Solución
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.
Go to PyPi and download Pygments.
Unzip it, then copy the source into the app engine folder for your project (probably best at the top-level).
Then you can just do
import pygments
as usual. If you want to put it in a subdirectory (saymypackages
), you have to change the import string, e.g.from mypackages import pygments
.
Otros consejos
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