ImportError: No module named 'pysqlite2'
来源:4-8 数据库ORM
米苏咪
2019-06-16
import sys
sys.path.append('../')
from flask import Flask, url_for
from imooc import route_imooc
from order.common.libs.UrlManager import UrlManager
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.register_blueprint(route_imooc, url_prefix='/immoc')
app.config['SQLALCHEMY_DATABASE_URL'] = 'mysql://root:abc123@127.0.0.1/mysql'
db = SQLAlchemy(app)
@app.route('/')
def hello_world():
url = url_for('index')
url1 = UrlManager.buildurl("/api")
url2 = UrlManager.buildstaticurl('/css/bootstrap.css')
msg = "Hello World :url:%s, url1:%s url2: %s" % (url, url1, url2)
app.logger.info(msg)
return msg
@app.route('/api')
def index():
return "Index page"
@app.route('/api/hello')
def hello():
from sqlalchemy import text
sql = text("select * from 'user'")
result = db.engine.execute(sql)
for row in result:
app.logger.info(row)
return "hello"
if __name__ == "__main__":
app.run(host='0.0.0.0',debug = True)
上面是代码 下面是报错信息 linux cento 平台
192.168.1.11 - - [16/Jun/2019 20:35:16] "GET / HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:22] "GET /api/hello HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 338, i n dbapi
from pysqlite2 import dbapi2 as sqlite
ImportError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 2314, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 1760, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/root/flasktest/order/hello.py", line 38, in hello
result = db.engine.execute(sql)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py", line 937, in engine
return self.get_engine()
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py", line 956, in get_engi ne
return connector.get_engine()
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py", line 561, in get_engi ne
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py", line 966, in create_e ngine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/sqlalchemy/engine/__init__.py", line 435, in create_ engine
return strategy.create(*args, **kwargs)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 343, i n dbapi
raise e
File "/usr/local/python3/bin/imooc_env/lib/python3.5/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 341, i n dbapi
from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name.
File "/usr/local/python3/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/python3/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
192.168.1.11 - - [16/Jun/2019 20:35:22] "GET /api/hello?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:22] "GET /api/hello?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:22] "GET /api/hello?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:23] "GET /api/hello?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:23] "GET /api/hello?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:23] "GET /api/hello?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:23] "GET /api/hello?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
192.168.1.11 - - [16/Jun/2019 20:35:23] "GET /api/hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
2回答
-
你好
如下应该写错了
app.config['SQLALCHEMY_DATABASE_URL'] = 'mysql://root:abc123@127.0.0.1/mysql'
正确是的
SQLALCHEMY_DATABASE_URI
012019-06-17 -
米苏咪
提问者
2019-06-16
export ops_config=local 这个export 也执行过了
00
相似问题