Importerror: No Module Named Psycopg2 After Install

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

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>.

No module named 'psycopg2'

It is possible that while following the installation tutorial you installed virtualenv, created some environment (like env1) and followed on to install django on that environment.

If so, than you are running django on that environment as well (otherwise it would not be installed). In order to install modules you need to first activate the environment and then use pip.

ImportError: No module named psycopg2 after install

The problem is that you installed psycopg2 as a superuser, i.e. using 'sudo'. When you run commands as a super user, the command gets executed in a different shell that has the superuser's environment, and as a result the package will be installed in a different location in the filesystem that may not be accessible to your 'normal' environment. You need to install the package again as a regular user, i.e. without the leading 'sudo' in order to use the package. In short, just run:

pip install psycopg2

ImportError: No module named 'psycopg2._psycopg'

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

PostgreSQL- ModuleNotFoundError: No module named 'psycopg2'

Yes, found a solution,

python -m pip install psycopg2-binary 

does the trick!



Related Topics



Leave a reply



Submit