1

I am using Python 3.7 and trying to use psycopg2 in my program. Only one line of code so far.

import psycopg2

I looked at various approaches given on Stack Overflow but didn't find anything helpful.

pip uninstall psycopg2

pip install psycopg2

pip install psycopg2-binary -t  .
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Manish Nankar
  • 37
  • 1
  • 8

2 Answers2

0

If you are using python3, then you should use pip3 for installing packages:

pip3 install psycopg2

By default, pip is for python-pip package and python2, and pip3 is for python3-pip package and python3. unless you have an alias that pip=pip3

Amin
  • 2,605
  • 2
  • 7
  • 15
0

Another potential issue that often causes ModuleNotFoundError issues is if you name your script the same as the module you're trying to import. In this case, check if your program is named psycopg2.

The solution is to rename your script to a name which doesn't conflict with the names of the imported modules.

Mous
  • 953
  • 3
  • 14