Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psycopg2 importError Python3.12 on Windows

I have a python script that I built over the last 2 weeks using python3.10. The script did run fine 100s of times until I reinstalled python/modules.

I recently upgraded to Python 3.12. I had to pip install all of the modules again but now for some reason when I try to run my script the psycopg2 module keeps failing with the follow error:

packages\psycopg2\__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: DLL load failed while importing _psycopg: The specified module could not be found.

I am running my script from Visual Studio Code 1.83 in a powershell prompt.

I have tried uninstalling, clearing pip cache and reinstalling.

I have tried suggested psycopg2-binary package.

I tried updating Microsoft Visual C++ update. I tried reinstalling python 312.

I assume this is some weird windows dependency issue. Can anyone please help me troubleshoot? I am happy to provide more information if needed.

like image 796
Curly Avatar asked Sep 08 '26 19:09

Curly


2 Answers

I had the same problem, unfortunately could not find any solution other than downgrading python version from 3.12 to 3.11.6, now it is working well.

like image 102
Centi Avatar answered Sep 10 '26 09:09

Centi


Should be releasing a fix for version 3.12 on Windows soon. https://github.com/psycopg/psycopg2/issues/1628

like image 32
Alexander Ku Avatar answered Sep 10 '26 08:09

Alexander Ku