Flask: Mongoengine ImportError: no module named json

Flask: Mongoengine ImportError: no module named json

我正在学习 http://docs.mongodb.org/ecosystem/tutorial/write-a-tumblelog-application-with-flask-mongoengine/

上的 mongo 教程

我到了配置 MongoEngine 和 Flask 的部分,将旧的 init.py 替换为以下代码:

from flask import Flask
from flask.ext.mongoengine import MongoEngine

app = Flask(__name__)
app.config["MONGODB_SETTINGS"] = {'DB': "my_tumble_log"}
app.config["SECRET_KEY"] = "KeepThisS3cr3t"

db = MongoEngine(app)

if __name__ == '__main__':
    app.run()

但是现在当我尝试 python manage.py runserver 时,我得到这个错误:

Traceback (most recent call last):
 File "manage.py", line 6, in <module>
    from tumbleblog import app
  File "/Users/<ME>/tumbleblog/__init__.py", line 2, in <module>
    from flask.ext.mongoengine import MongoEngine
  File "/Users/<ME>/myproject/lib/python2.7/site-packages/flask_mongoengine/__init__.py", line 13,       in <module>
    from .json import overide_json_encoder
  File "/Users/<ME>/myproject/lib/python2.7/site-packages/flask_mongoengine/json.py", line 1, in <module>
    from flask.json import JSONEncoder
ImportError: No module named json

这是我的 manage.py 文件:

# Set the path
import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from flask.ext.script import Manager, Server
from tumbleblog import app

manager = Manager(app)

# Turn on debugger by default and reloader
manager.add_command("runserver", Server(
    use_debugger = True,
    use_reloader = True,
    host = '0.0.0.0')
)

if __name__ == "__main__":
    manager.run()

这里是点冻结:

Flask==0.9
Flask-Script==2.0.5
Flask-WTF==0.10.3
Jinja2==2.6
WTForms==2.0.1
Werkzeug==0.8.3
bottle==0.12.8
bson==0.3.3
distribute==0.6.15
flask-mongoengine==0.7.1
gnureadline==6.3.3
gunicorn==0.17.2
ipython==2.1.0
lxml==3.4.0
mongoengine==0.8.7
pymongo==2.7.2
pypm==1.3.4
pythonselect==1.3
pytz==2014.10
requests==2.2.1
stevedore==0.15
virtualenv==1.6.1
virtualenv-clone==0.2.5
virtualenvwrapper==4.2
wsgiref==0.1.2

可能是什么问题?我的 mongo 软件似乎都是最新的。

您需要将 Flask 升级到 0.10 或安装旧版本 (0.8.4) 的 flask-wtf。

来源: Flask on Ubuntu is unable to find Flask.json