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
Answer from Matthew Weber on Stack Overflow
Discussions

Error loading psycopg2 module: No module named 'psycopg2'
Hi all, First of all, I've read all the posts I could find about this problem to no avail :( I've got an up&running default webapp with python3 and django already working with default d... More on github.com
🌐 github.com
9
May 26, 2021
Python 3.11.0 ModuleNotFoundError: No module named 'psycopg2._psycopg' 🐛
Bug Report At what date and time did you most recently experience the problem? 2022-12-22T15:52:45.994388013Z Where did you experience the problem? E.g. Azure Web Apps, Azure Functions, Azure Conta... More on github.com
🌐 github.com
21
December 22, 2022
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2._psycopg'
My site was working well in cpanel. when i add it to google search console for seo, after one day I am seeing such error: We’re sorry, but something went wrong. The issue has been logged for investigation. Please try again later. Here is my Passengers.py file My os is Windows. More on forum.djangoproject.com
🌐 forum.djangoproject.com
3
0
November 11, 2022
python - ModuleNotFoundError: No module named 'psycopg2' - Stack Overflow
I'm using Mac os. I installed pyscopg2 successfully (pip3 install psycopg2) But when I try to import psycopg2 I get the following message: Traceback (most recent call last): File " ", More on stackoverflow.com
🌐 stackoverflow.com
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1326206 › modulenotfounderror-no-module-named-psycopg2-psyco
ModuleNotFoundError: No module named 'psycopg2._psycopg'. Please check the requirements.txt file for the missing module. - Microsoft Q&A
July 7, 2023 - python3.9 -m venv worker_venv source worker_venv/bin/activate sudo apt-get update sudo pip3 install --upgrade pip sudo apt install build-essential libpq-dev python3-dev sudo pip3 install psycopg2 --upgrade sudo pip3 install psycopg2-binary --upgrade sudo pip3 install --target="./.python_packages/lib/site-packages" psycopg2 --upgrade sudo pip3 install --target="./.python_packages/lib/site-packages" psycopg2-binary --upgrade sudo pip3 install --target="./.python_packages/lib/site-packages" -r ./requirements.txt --upgrade
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-modulenotfounderror-no-module-named-psycopg2-in-python
How to Fix 'ModuleNotFoundError: No Module Named psycopg2' in Python - GeeksforGeeks
July 23, 2025 - Another reason for the error might be a typo or incorrect naming when trying to import the psycopg2 module. Python is case-sensitive, so ensure that the module name is spelled correctly. ... Below, are the approaches to solve “Modulenotfounderror: No Module Named ‘psycopg2′”.
🌐
GitHub
github.com › psycopg › psycopg2 › issues › 1282
Error loading psycopg2 module: No module named 'psycopg2' · Issue #1282 · psycopg/psycopg2
May 26, 2021 - (env) PS D:\Users\llagos.NB-KEYONE15\Visual Studio projects\ecommerce-psql> python manage.py makemigrations Traceback (most recent call last): File "D:\Users\llagos.NB-KEYONE15\Visual Studio projects\ecommerce-psql\env\lib\site-packages\django\db\backends\postgresql\base.py", line 25, in import psycopg2 as Database ModuleNotFoundError: No module named 'psycopg2' ...
Author   psycopg
🌐
GitHub
github.com › microsoft › Oryx › issues › 1767
Python 3.11.0 ModuleNotFoundError: No module named 'psycopg2._psycopg' 🐛 · Issue #1767 · microsoft/Oryx
December 22, 2022 - Bug Report At what date and time did you most recently experience the problem? 2022-12-22T15:52:45.994388013Z Where did you experience the problem? E.g. Azure Web Apps, Azure Functions, Azure Conta...
Author   microsoft
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › python-no-module-named-psycopg2
ModuleNotFoundError: No module named 'psycopg2' in Python | bobbyhadz
April 8, 2024 - The Python ModuleNotFoundError: No module named 'psycopg2' occurs when we forget to install the `psycopg2-binary` module before importing it.
🌐
GitHub
github.com › apache › superset › discussions › 31431
ModuleNotFoundError: No module named 'psycopg2' during k8 installation · apache/superset · Discussion #31431
To resolve the "ModuleNotFoundError: No module named 'psycopg2'" error during the deployment of Superset using a Helm chart, you should ensure that the correct version of psycopg2 is pinned.
Author   apache
🌐
Django Forum
forum.djangoproject.com › using django › deployment
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2._psycopg' - Deployment - Django Forum
November 11, 2022 - My site was working well in cpanel. when i add it to google search console for seo, after one day I am seeing such error: We’re sorry, but something went wrong. The issue has been logged for investigation. Please try again later. Here is my Passengers.py file My os is Windows.
🌐
Reddit
reddit.com › r/django › why am i getting 'modulenotfounderror' after installing psycopg2 and running 'python manage.py migrate' in my django project?
Why am I getting 'ModuleNotFoundError' after installing psycopg2 and running 'python manage.py migrate' in my Django project? : r/django
November 25, 2024 - Despite the lack of number in the package name, this package is the successor of psycopg2. Please use the psycopg2 package if you are maintaining an existing program using psycopg2 as a dependency. If you are developing something new, Psycopg 3 is the most current implementation of the adapter.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-no-module-named-psycopg2-in-python-aws
How to Fix 'No Module Named psycopg2' in Python AWS - GeeksforGeeks
July 23, 2025 - The error "No module named psycopg2" in AWS Lambda occurs when the Lambda function is unable to locate the psycopg2 library, which is essential for interacting with PostgreSQL databases from Python code.
🌐
YouTube
youtube.com › watch
How to Resolve ModuleNotFoundError: No module named 'psycopg2._psycopg' in Python - YouTube
Having trouble with the error "ModuleNotFoundError: No module named 'psycopg2._psycopg'" in Python? Discover the steps to resolve it, especially on Windows.-...
Published   January 20, 2025
Views   62
🌐
Django Forum
forum.djangoproject.com › using django › mystery errors
psycopg2 Error loading psycopg2 or pyscopg module - Mystery Errors - Django Forum
May 12, 2024 - Hello, im trying to use postgres to my django app and im following a tutorial, im on an activated virtual enviroment and i’ve installed psycopg2==2.9.9 psycopg2-binary==2.9.9 (this is from my requirements.txt file) then i modified the settings from my project to this DATABASES = { ‘default’: ...
Top answer
1 of 1
3

I'm also facing the same problem. It took me 2 days to pulled out my hair until I found the solution.

What I've been tried

Here's what I have been doing to solve this issue BUT DIDN'T SOLVE THE PROBLEM. I hope it will help anybody else who has the same problem.

  1. Install "psycopg2" and "psycopg2-binary"
    • pip install psycopg2
    • pip install psycopg2-binary
  2. Install "libpq-dev"
    • sudo apt install libpq-dev
  3. Install "python-psycopg2" and "python3-psycopg2"
    • sudo apt install python-psycopg2 python3-psycopg2
  4. Install "python-dev" and "python3-dev" and "python3.9-dev"
    • sudo apt install python-dev python3-dev python3.9-dev
  5. Install "python-setuptools"
    • sudo apt install python-setuptools

Unfortunately, none of my effort above solve my problem.


What's the solution

So, here's my solution that I've been try and IT WORKS

Install the latest mod_wsgi from Github.

You should install this latest 'mod_wsgi' in order to your wsgi able to use Psycopg2 library. Here's my step to do it :

  1. Go to release page mod_wsgi on Github (https://github.com/GrahamDumpleton/mod_wsgi/releases)
  2. Download the file from latest version. As I write this, the latest version is 4.7.1 (https://github.com/GrahamDumpleton/mod_wsgi/archive/4.7.1.tar.gz)
  3. Follow the installation guide from official docs.
    1. Unpacking source code
      • tar xvfz mod_wsgi-4.7.1.tar.gz
    2. Configure source code
      • ./configure
    3. Build the source code and install
      • make
      • make install
    4. Restart apache server
      • sudo service apache2 restart

This solution has works on my machine (Ubuntu 18.04 & Python 3.9 Venv).


Alternative solution

Here's some solution from others.

  1. Saray Chak's solution
🌐
AWS re:Post
repost.aws › questions › QUfcS3lCR0RX6mWp7MVj3b0w › cannot-seem-to-import-psycopg2-in-aws-glue-3-0
Cannot seem to import psycopg2 in AWS Glue 3.0 | AWS re:Post
May 11, 2022 - If you prefer to avoid building psycopg2 from source, please install the PyPI 'psycopg2-binary' package instead.