无法加载插件:sqlalchemy.dialects:sqlite3
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法加载插件:sqlalchemy.dialects:sqlite3相关的知识,希望对你有一定的参考价值。
我正在学习使用Python here创建API。我已准备好所有内容并下载了数据库,但是当我运行我的应用程序时,我收到以下错误:
Traceback (most recent call last):
File "app.py", line 7, in <module>
e = create_engine("sqlite3:///salaries.db")
File "C:Python27libsite-packagessqlalchemyengine\__init__.py", line 387, in create_engine
return strategy.create(*args, **kwargs)
File "C:Python27libsite-packagessqlalchemyenginestrategies.py", line 56, in create
entrypoint = u._get_entrypoint()
File "C:Python27libsite-packagessqlalchemyengineurl.py", line 139, in _get_entrypoint
cls = registry.load(name)
File "C:Python27libsite-packagessqlalchemyutillanghelpers.py", line 212, in load
(self.group, name))
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqlite3
我在错误地加载正确插件的地方错了什么?
from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
e = create_engine("sqlite3:///salaries.db")
app = Flask(__name__)
api = Api(app)
class DepartmentsMeta(Resource):
def get(self):
conn = e.connect()
query = conn.execute("select distinct DEPARTMENT from salaries")
return {"departments": [i[0] for i in query.cursor.fetchall()]}
class DepartmentSalary(Resource):
def get(self, department_name):
conn = e.connect()
query = conn.execute("select * from salaries where Department='%s'" % department_name)
result = {"data": [dict(zip(tuple(query.keys()), i))] for i in query.cursor}
return result
api.add_resource(DepartmentSalary, "/dept/<string:department_name>")
api.add_resource(DepartmentsMeta, "/department")
if __name__ == "__main__":
app.run()
答案
请尝试替换此行:
e = create_engine("sqlite3:///salaries.db")
同
e = create_engine("sqlite:///salaries.db")
以上是关于无法加载插件:sqlalchemy.dialects:sqlite3的主要内容,如果未能解决你的问题,请参考以下文章