Nick
Nick

Reputation: 1934

Flask: Mongoengine ImportError: no module named json

I'm following the mongo tutorial at http://docs.mongodb.org/ecosystem/tutorial/write-a-tumblelog-application-with-flask-mongoengine/

I got to the part where you configure MongoEngine and Flask, replacing the old init.py with this code:

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()

But now when I try python manage.py runserver, I get this error:

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

Here's my manage.py file:

# 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()

Here's pip freeze:

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

What could be the problem? It seems like all my mongo software is up to date.

Upvotes: 0

Views: 2040

Answers (1)

TuTTe
TuTTe

Reputation: 164

You need to upgrade Flask to 0.10 or install an older version (0.8.4) of flask-wtf.

Source: Flask on Ubuntu is unable to find Flask.json

Upvotes: 3

Related Questions