Python Flask ModuleNotFoundError: No module named ‘psycopg2’

When you working with Python Flask application, you may found the following error:

builtins.ModuleNotFoundError
ModuleNotFoundError: No module named 'psycopg2'

This means you want to use Python to talk to your PostgreSQL database, without install the psycopg2 plugin.

You can simply apply the following pip install command, and you should be fine:

pip install psycopg2

And if you working with postgresql database table. You may experience the following error when you try to talk to the database.

sqlalchemy.exc.OperationalError
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied
 (Background on this error at: http://sqlalche.me/e/e3q8)

That actually means you have not provide the username, password for connecting to your database. In this case, you need to check your db connection. You have to make sure your connection should be follow the following pattern:

postgresql://user:password@localhost:5432/database_name