Syntax error in jinja 2 library

梦想的初衷 提交于 2019-12-20 04:19:07

问题


For running the IPython Notebook on a suse Linux server, I needed to install the jinja2 library:

pip-3.2 install jinja2

Installation printed a syntax error but also said "installation successful".

On import, I get the following error:

In [1]: import jinja2
  File "/usr/local/lib/python3.2/site-packages/jinja2/environment.py", line 639
    u'\xff\xff\xff\xff'.encode('iso-8859-15')
                      ^
SyntaxError: invalid syntax

Bug in the jinja2 package? Any way for me to fix this?


回答1:


Jinja2 only supports Python 3.3 and up, you are trying to install it for Python 3.2. Quoting from the documentation:

Jinja 2.7 brings experimental support for Python >=3.3.

Python 3.3 added support for u'..' string literals to make it easier to write compatible code that runs both on Python 2 and 3, which Jinja2 makes use of.

You'll either have to upgrade to Python 3.3, or pick a different templating library or use an earlier version.

The requirement was upgraded to 3.3 in version 2.7 (see the changelog), so you could try installing 2.6:

pip install jinja2==2.6



回答2:


Install jinja 2.5, using:

easy_install jinja2==2.5

That solved the problem for me (happily).



来源:https://stackoverflow.com/questions/18252804/syntax-error-in-jinja-2-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!