Can't load plugin: sqlalchemy.dialects:sqlite3

Question:

I’m learning to create API’s using Python here. I’ve gotten everything ready and downloaded the database, however when I run my app I’m getting the following error:

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

What am I doing wrong to where it will not load the correct plugin?

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()
Asked By: User9123

||

Answers:

Please try replacing this line:

e = create_engine("sqlite3:///salaries.db")

with

e = create_engine("sqlite:///salaries.db")
Answered By: Alan Zhiliang Feng

I got the same problem. I’ve solved it by:

pip3 uninstall flask_sqlalchemy and pip3 install flask-sqlalchemy==2.5.1 because big changes with flask-sqlalchemy==3.0 SQLite DB in memory are not set as default in this version.

Hope it helps you.

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.