我想使用flask-mongoengine开发应用程序,但在启动应用程序时出现importError
我的烧瓶run.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from app import app
if __name__ == '__main__':
app.run(debug=True)
我的应用程序 init .py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
import flask_mongoengine
from flask_mongoengine import MongoEngine
app = Flask(__name__)
app.config['MONGODB_SETTINGS'] = {
'db': 'datasync_datax',
'host': '192.168.100.85',
'port': 27017
}
db = MongoEngine()
db.init_app(app)
启动时遇到的问题:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/huan/sources/python-sources/bt-ware-datasync-datax/run.py", line 4, in <module>
from app import app
File "/Users/huan/sources/python-sources/bt-ware-datasync-datax/app/__init__.py", line 5, in <module>
import flask_mongoengine
File "/Library/Python/2.7/site-packages/flask_mongoengine/__init__.py", line 6, in <module>
import mongoengine
File "/Library/Python/2.7/site-packages/mongoengine/__init__.py", line 3, in <module>
from mongoengine import document
File "/Library/Python/2.7/site-packages/mongoengine/document.py", line 44, in <module>
class EmbeddedDocument(six.with_metaclass(DocumentMetaclass, BaseDocument)):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py", line 566, in with_metaclass
return meta("NewBase", bases, {})
File "/Library/Python/2.7/site-packages/mongoengine/base/metaclasses.py", line 151, in __new__
CachedReferenceField) = mcs._import_classes()
File "/Library/Python/2.7/site-packages/mongoengine/base/metaclasses.py", line 243, in _import_classes
Document = _import_class('Document')
File "/Library/Python/2.7/site-packages/mongoengine/common.py", line 27, in _import_class
from mongoengine.fields import __all__ as fields
File "/Library/Python/2.7/site-packages/mongoengine/fields.py", line 34, in <module>
from mongoengine.document import Document, EmbeddedDocument
ImportError: cannot import name Document
我在python2.7中的开发环境
我不知道怎么了。
pymongo,mongoengine,flask-mongoengine已安装
答案 0 :(得分:0)
问题已经解决。
我更新了我的flask-mongoengine库!
sudo pip install --upgrade flask-mongoengine