ModuleNotFoundError: No module named ‘psycopg2’

psycopg2 module is used to connect to PostgreSQL Server using Python. But, if you receive below error means,you have not installed psycopg2 module.

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'psycopg2'

Solution:


We have to install psycopg2 on Windows or Linux.

1) Install psycopg2 on windows with the below command.

pip install psycopg2 or pip install psycopg2-binary or pip3 install psycopg2

C:\Users\karunakar\Desktop\Py Practice>pip install psycopg2 Collecting psycopg2 Downloading https://files.pythonhosted.org/packages/79/ad/327e9c1e09b91e57294eb9a38492fcb000f15c028a1b716714fee5be802e/psycopg2-2.8.4-cp38-cp38-win32.whl (986kB) |████████████████████████████████| 993kB 133kB/s Installing collected packages: psycopg2 Successfully installed psycopg2-2.8.4

2. Install psycopg2 on Linux.

sudo apt-get install libpq-dev

3. Now try to import the psycopg2 module. Then, you will not get the error.

Leave a Reply

Your email address will not be published. Required fields are marked *