我遵循本教程:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database 那家伙说我应该创建一个脚本来创建db:
#!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))
但是当我尝试运行该脚本时,我得到:
/home/devuser/wapp/flask/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.
warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.')
Traceback (most recent call last):
File "./db_create.py", line 7, in <module>
db.create_all()
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 972, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 964, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 910, in get_engine
return connector.get_engine()
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 545, in get_engine
self._engine = rv = sqlalchemy.create_engine(info, **options)
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/devuser/wapp/flask/lib/python2.7/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 339, in dbapi
raise e
ImportError: No module named pysqlite2
This Stackoverflow帖子不起作用。 this
当我尝试安装pysqlite时this帖子说(使用pip install pysqlite)我得到:
Collecting pysqlite
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Using cached pysqlite-2.8.1.tar.gz
Complete output from command python setup.py egg_info:
Only Python 2.7 is supported.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JoH01e/pysqlite
你能帮我吗?