Error: No module named 'psycopg2'

Hi there,

I have completed the PostgreSQL installation mission, ran ‘conda install psycopg2’ in the Anaconda Powershell, but when I run the given code:

import psycopg2
conn = psycopg2.connect(dbname=“postgres”, user=“postgres”)
cursor = conn.cursor()
cursor.execute(“CREATE TABLE notes(id integer PRIMARY KEY, body text, title text)”)
conn.close()

in Jupyter notebooks, I get the error: No module named ‘psycopg2’.

Can anybody help me please?

Many thanks,
Suzie

1 Like

Hello @suzieamey, welcome to the community!

Try installing it with pip install psycopg2. I did and it works on Jupyter.

1 Like

Hi Otavios,

Thank you for your reply! I got there in the end with conda after I updated it.

Thanks for your help :slight_smile:

1 Like