Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'psycopg2._psycopg'

When I try to import psycopg2 it show below log for me:

Traceback (most recent call last):   File "D:/Desktop/learn/python/webcatch/appserver/testpgsql.py", line 2, in <module>     import psycopg2   File "D:/Desktop/learn/python/webcatch/appserver/webcatch/lib/site-packages/psycopg2-2.6.1-py3.5-win32.egg/psycopg2/__init__.py", line 50, in <module>     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: No module named 'psycopg2._psycopg' 

How can I solve it? My platform is win10 (64) and version is python 3.5

like image 845
sappy Avatar asked Mar 19 '16 14:03

sappy


People also ask

How do you fix ModuleNotFoundError No module named psycopg2?

The Python "ModuleNotFoundError: No module named 'psycopg2'" occurs when we forget to install the psycopg2-binary module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install psycopg2-binary command.

How do I install psycopg2 on Windows 10?

To install this module follow the below steps. If python is not installed in your system, then you can install it running the given command in your command prompt. Step 2: Open the command prompt and run the below command to install psycopg2-binary. If it shows successfully installed then you are good to go.


1 Answers

Eureka! I pulled my hair out for 2 days trying to get this to work. Enlightenment came from this SO Question. Simply stated, you probably installed psycopg2 x64 version like I did, not realizing your python version was 32-bit. Unistall your current psycopg2, then:

Download: psycopg2-2.6.1.win32-py3.4-pg9.4.4-release.exe from HERE, then run the following in a Terminal:

C:\path\to\project> easy_install /path/to/psycopg2-2.6.1.win32-py3.4-pg9.4.4-release.exe C:\path\to\project> python manage.py makemigrations C:\path\to\project> python manage.py migrate 

You may also need to (re)create super user with:

C:\path\to\project> python manage.py createsuperuser 
like image 58
Matthew Weber Avatar answered Sep 24 '22 17:09

Matthew Weber