ImportError:无法导入名称异常FLASK - Python

时间:2016-01-07 15:02:36

标签: python flask

我在Python中使用SQLite和Flask。我的问题是我尝试创建数据库但是我收到错误" ImportError:无法导入名称异常"

python db_create.py

db_create.py

#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))

错误

Traceback (most recent call last):
  File "db_create.py", line 2, in <module>
    from migrate.versioning import api
  File "/home/desarrollo3/.local/lib/python2.7/site-packages/migrate/versioning/api.py", line 33, in <module>
    from migrate.versioning import (repository, schema, version,
  File "/home/desarrollo3/.local/lib/python2.7/site-packages/migrate/versioning/schema.py", line 10, in <module>
    from sqlalchemy import exceptions as sa_exceptions
ImportError: cannot import name exceptions

1 个答案:

答案 0 :(得分:1)

要解决此问题,我必须安装sqlalchemy-migrate包:

pip install sqlalchemy-migrate