Python 2.7 我在使用flask SQL alchemy提交到sqlite3时遇到导入错误

Python 2.7 我在使用flask SQL alchemy提交到sqlite3时遇到导入错误,python-2.7,sqlalchemy,flask,pycharm,whoosh,Python 2.7,Sqlalchemy,Flask,Pycharm,Whoosh,奇怪的是,我只是尝试使用flask sqlalchemy更新sqlite3数据库中的一个值 anime = Anime.query.get(2) anime.finished=2 db.session.add(anime) db.session.commit() 在提交之前一切正常,然后我得到一个“ImportTerror:没有名为pycharm\u re的模块” 是的,我正在使用PyCharmCE IDE,但没有PyCharm基导入。当我在终端中尝试此操作时,导致了相同的错误 最后,我发现它

奇怪的是,我只是尝试使用flask sqlalchemy更新sqlite3数据库中的一个值

anime = Anime.query.get(2)
anime.finished=2
db.session.add(anime)
db.session.commit()
在提交之前一切正常,然后我得到一个“ImportTerror:没有名为pycharm\u re的模块”

是的,我正在使用PyCharmCE IDE,但没有PyCharm基导入。当我在终端中尝试此操作时,导致了相同的错误

最后,我发现它可能与嗖嗖炼金术有关,我以前在models.py中有2个嗖嗖指数(app,SomeClass)时遇到过这个错误

我在PyCharmCE中使用Python2.7.3,在Terminal中使用2.7.5。系统是OSX10.9.2。 整个错误日志:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/windrunner/bangumi/bangumi/views.py", line 76, in edit_anime
    db.session.commit()
  File "/Library/Python/2.7/site-packages/sqlalchemy/orm/scoping.py", line 149, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/sqlalchemy/orm/session.py", line 721, in commit
    self.transaction.commit()
  File "/Library/Python/2.7/site-packages/sqlalchemy/orm/session.py", line 361, in commit
    self.session.dispatch.after_commit(self.session)
  File "/Library/Python/2.7/site-packages/sqlalchemy/event.py", line 372, in __call__
    fn(*args, **kw)
  File "/Library/Python/2.7/site-packages/flask_sqlalchemy/__init__.py", line 170, in session_signal_after_commit
    models_committed.send(session.app, changes=d.values())
  File "/Library/Python/2.7/site-packages/blinker/base.py", line 267, in send
    for receiver in self.receivers_for(sender)]
  File "/Library/Python/2.7/site-packages/flask_whooshalchemy.py", line 242, in _after_flush
    index = whoosh_index(app, values[0][1].__class__)
  File "/Library/Python/2.7/site-packages/flask_whooshalchemy.py", line 168, in whoosh_index
    _create_index(app, model))
  File "/Library/Python/2.7/site-packages/flask_whooshalchemy.py", line 190, in _create_index
    if whoosh.index.exists_in(wi):
  File "/Library/Python/2.7/site-packages/whoosh/index.py", line 136, in exists_in
    ix = open_dir(dirname, indexname=indexname)
  File "/Library/Python/2.7/site-packages/whoosh/index.py", line 123, in open_dir
    return FileIndex(storage, schema=schema, indexname=indexname)
  File "/Library/Python/2.7/site-packages/whoosh/index.py", line 421, in __init__
    TOC.read(self.storage, self.indexname, schema=self._schema)
  File "/Library/Python/2.7/site-packages/whoosh/index.py", line 656, in read
    schema = pickle.loads(stream.read_string())
ImportError: No module named pycharm_re

似乎是因为我在使用whoosh_index()函数运行后添加了第二行whoosh_index(),然后不允许进行任何编辑,我将在返回后进行更多尝试。代码中的另一个问题是您再次将
anime
对象添加到会话中。没用。获取实体时,它们已附加到默认的
db.session
。只有在创建新实体时,才需要调用
all