sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
Questions : sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00
2381
I'm trying to connect to a Postgres database anycodings_psycopg2 with SQLAlchemy. I've installed psycopg2. anycodings_psycopg2 However, I get the error anycodings_psycopg2 sqlalchemy.exc.NoSuchModuleError: Can't load anycodings_psycopg2 plugin: sqlalchemy.dialects:postgres. How do anycodings_psycopg2 I configure SQLAlchemy to connect to anycodings_psycopg2 PostgreSQL?
from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://username@localhost:5432/template1" db = SQLAlchemy(app)Total Answers 6
30
Answers 1 : of sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
The URI should start with postgresql:// anycodings_postgresql instead of postgres://. SQLAlchemy used anycodings_postgresql to accept both, but has removed support anycodings_postgresql for the postgres name.
0
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00Answer Link
mRahman
2
Answers 2 : of sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
SQLAlchemy 1.4 removed the deprecated anycodings_postgresql postgres dialect name, the name anycodings_postgresql postgresql must be used instead now. The anycodings_postgresql dialect is the part before the :// in anycodings_postgresql the URL. SQLAlchemy 1.3 and earlier anycodings_postgresql showed a deprecation warning but still anycodings_postgresql accepted it.
To fix this, rename postgres:// in the anycodings_postgresql URL to postgresql://.
This error currently shows up when anycodings_postgresql working with Heroku, which uses postgres anycodings_postgresql in the DATABASE_URL they provide, which anycodings_postgresql you probably use for anycodings_postgresql SQLALCHEMY_DATABASE_URI. To work around anycodings_postgresql this until they update it, update the anycodings_postgresql variable in the Heroku dashboard to use anycodings_postgresql postgresql.
0
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00Answer Link
jidam
2
Answers 3 : of sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
The problem in heroku have been resolved anycodings_postgresql by using simple python url replace code
import os import re uri = os.getenv("DATABASE_URL") # or other relevant config var if uri and uri.startswith("postgres://"): uri = uri.replace("postgres://", "postgresql://", 1) # rest of connection code using the connection string `uri`source : anycodings_postgresql //help.heroku.com/ZKNTJQSK/why-is-sqlalchemy-1-4-x-not-connecting-to-heroku-postgres
0
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00Answer Link
jidam
6
Answers 4 : of sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
# production or dev DB try: prodURI = os.getenv('DATABASE_URL') prodURI = prodURI.replace("postgres://", "postgresql://") app.config['SQLALCHEMY_DATABASE_URI'] = prodURI except: app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///MYDATABASE'
I tried all the above answers, but only anycodings_postgresql this worked for me. I followed Heroku's anycodings_postgresql official suggestion (mentioned in anycodings_postgresql previous comments), but no luck. I think anycodings_postgresql taking off the 1 at the end of replace() anycodings_postgresql may have helped.
0
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00Answer Link
joy
6
Answers 5 : of sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
As @Kaitlin Berryman said the Heroku anycodings_postgresql official answer is not working, to avoid anycodings_postgresql putting your DB credentials add this anycodings_postgresql before db.create_all():
# create the database and the db table import os import re uri = os.getenv("DATABASE_URL") # or other relevant config var if uri.startswith("postgres://"): uri = uri.replace("postgres://", "postgresql://", 1) app.config['SQLALCHEMY_DATABASE_URI'] = uri0
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00Answer Link
raja
3
Answers 6 : of sqlalchemy.exc.NoSuchModuleError: Cant load plugin: sqlalchemy.dialects:postgres
To fix this, rename postgres:// in the anycodings_postgresql URL to postgresql+psycopg2://.
0
2022-09-23T12:58:58+00:00 2022-09-23T12:58:58+00:00Answer Link
jidam