Search code examples
pythonpsycopg2tweepy

ModuleNotFoundError: No module named 'psycopg2' (But it is installed)


I've been stuck on a part of a Udemy course. Even the (very helpful) tutor on there has run of ideas. When I try and run my script I get:

ModuleNotFoundError: No module named 'psycopg2'

I've done pip install psycopg2 and pip install psycopg2-2.8.4-cp37-cp37m-win_amd64.whl. Both result in 'requirement already satisfied'. I tried CTRL+SHIFT+P, Select Interpreter, and got the same problem with all of the three options. Only difference is Python3.8.0 gives me a Unable to import 'psycopg2' pylint(import-error) [1,1] error as well.

C:\Python\Database>pip install psycopg2
Requirement already satisfied: psycopg2 in c:\users\jeff\anaconda3\lib\site-packages (2.8.4)

C:\Python\Database>script1.py
Traceback (most recent call last):
  File "C:\Python\Database\script1.py", line 1, in <module>
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

Edit

I still can't figure this out. And now I just got the same problem with Tweepy. ModuleNotFoundError: No module named 'tweepy' after I'd just successfully installed it. And similar error in the problems tab on VSC Unable to import 'tweepy' pylint(import-error) [1,1].


Solution

  • Psycopg project has modified the way they distribute the package. Starting from version 2.8.0, psycopg2 wheel on Pypi is a source distribution. To get the same package you used to install, you have to

    pip install psycopg2-binary
    

    Explanations can be found in psycopg-2.7.4 release note:

    The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: </docs/install.html#binary-install-from-pypi>.