Skip to content Skip to sidebar Skip to footer

Attributeerror: 'nonetype' Object Has No Attribute '_instantiate_plugins' (cannot Import Create_engine)

import os from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker engine=create_engine(os.getenv('DATABASE_URL')) db = scoped_session(session

Solution 1:

just use this as url "postgresql://username:password@host:port/database" directly pass these values inside your create_engine("postgresql://username:password@host:port/database")

I was having the same problem now its gone.That worked for me. Only thing important to mention is that I got a different error altogether after creating the new user and database and moving the tables. The error was '

'' ModuleNotFoundError: No module named 'psycopg2' '''

and the solution was running: pip3 install psycopg2-binary

PS: URL details with you details.

Solution 2:

It looks like os.getenv("DATABASE_URL") is returning None. Calling create_engine(None) give you this error. Is DATABASE_URL defined in your environment variable ?

Solution 3:

instead of

engine=create_engine(os.getenv("DATABASE_URL"))
   db = scoped_session(sessionmaker(bind=engine))

type this with your url:

engine = create_engine("postgresql://scott:tiger@localhost/mydatabase")
   db = scoped_session(sessionmaker(bind=engine))

Solution 4:

To avoid typing your postgresql connection (including password) in your code define your environment variable in your terminal according this:

source ~/.bash_profile

Or you can use the short form of the command:

. ~/.bash_profile

This executes .bash_profile file in the current shell.

Additional advices concerning reloading .bash_profile can be found in the comments here.

Post a Comment for "Attributeerror: 'nonetype' Object Has No Attribute '_instantiate_plugins' (cannot Import Create_engine)"