ModuleNotFoundError: No module named 'psycopg2' in ipython

Question:

This question has been asked before but none of the answers are unsatisfactory condition. I am trying to set up a PostgreSQL database for pandas with jupyter notebook (ipython) always I have following error ModuleNotFoundError: No module named ‘psycopg2’ the same I have connect with my Django project its working fine.

for this I have Installed following packages even I facing same issue. I am using ubuntu 18.04 bionic verion.

sudo apt-get install python3-psycopg2
pip3 install psycopg2-binary

enter image description here

Asked By: Suganesh Kumar

||

Answers:

Maybe you installed psycopg2 in ubuntu’s default python and you are trying notebook in anaconda’s environment. First try installing jupyter-notebook in virtualenv where psycopg2 works for django. If it works there then its an issue of different environment.

Answered By: Hemant Mehra

in the notebook cell, execute:

!pip install psycopg2-binary
Answered By: Ferris

Finally I have a solution for this. I just installed following package and its made my postgres connection.

conda install psycopg2
Answered By: Suganesh Kumar

For me, I was using a virtual environment. When I try yo execute:

!pip install psycopg2-binary

It gaves me:

bad interpreter: No such file or directory

When I tried to install the package i need, (in that case psycopg2) like that:

!python3 -m pip install psycopg2-binary

It worked for me.

Answered By: sbgocmez