Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named psycopg2

I have Django project which uses postgresql 9. I installed psycopg2 and when I run project I receive 'Error loading psycopg2 module: dll load failed'. I met this issue for the first time. I have windows 7 x64 with python2.7. How can I solve this one?

like image 758
szaman Avatar asked Nov 28 '11 19:11

szaman


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.

What is psycopg2 module in Python?

Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection).


2 Answers

I had the same problem, it was that psycopg2 does not install well in Windows with _easy_install_, I followed the instructions on the follow SO answer:

Installing psycopg2 (postgresql) in virtualenv on windows

You need to manually install the psycopg2 exe file:

psycopg2-2.4.2.win-amd64-py2.7-pg9.0.4-release.exe

like image 186
Roberto Alarcon Avatar answered Oct 06 '22 00:10

Roberto Alarcon


I know this is going to haunt me again or as nwcell puts it:

Every time I need to set up psycopg2 on windows, I wind up wanting to shoot something.

I actually have a machine with it working and I've been at pains to setup another machine. I installed Python 3.8 and the old PC has 3.7.4. The main difference was the file:

C:\project\venv\Lib\site-packages\psycopg2_psycopg.cp37-win32.pyd

On the new PC it was showing as AMD64. I eventually uninstalled 3.8 and reverted back to 3.7.4, then I copied the files from the old PC to the new and then I hit this error:

https://stackoverflow.com/a/37819509/495455

Going to a WayBackMachine version of the stickpeople:

https://web.archive.org/web/20191003103502/http://www.stickpeople.com/projects/python/win-psycopg/

I didn't install the exe, I simply did a pip install -Iv psycopg2-binary==2.8.4 at which point it started working. So I'm thinking the latest version doesn't work, for me 2.8.4 still works: https://pypi.org/project/psycopg2/#files

It's something to do with x64 as everything I tried with AMD64 didn't work and I spent ages on it.

like image 24
Jeremy Thompson Avatar answered Oct 06 '22 00:10

Jeremy Thompson