psycopg2 Error loading psycopg2 or pyscopg module

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’: {
‘ENGINE’: ‘django.db.backends.postgresql’,
‘NAME’: ‘commerce’,
‘USER’: ‘USER’,
‘PASSWORD’: ‘PASSWORD’,
}
}

and, since i was using sqlite im migrating the sqlite data to the postgres db and im using
python -Xutf8 manage.py dumpdata --indent=2 --output=commerce_data.json

then when i run that command im getting this
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 or psycopg module

i’ve installed via pip: pip install psycopg2-binary psycopg

what im doing wrong?

also, if i open a terminal and run something like this

import psycopg2

i get ModuleNotFoundError: No module named ‘psycopg2’

@Kubz
Did you forget to activate the environment ??

DATABASES = {
‘default’: {
    ‘ENGINE’: ‘django.db.backends.postgresql’,
    ‘NAME’: ‘commerce’,
    ‘USER’: ‘USER’,
    ‘PASSWORD’: ‘PASSWORD’,
    'HOST' : YOU-MISS-THIS,  # localhost
    'PORT': YOU-MISS-THIS,   # 5432
    }
}

Try to check postgresql.service sudo systemctl status postgresql and restart it .
We have no complete vision about your issue but I am guessing…
Hope That helps.

I got the same error and found no answer around. However it worked for me when I run the server with python3.11 instead of 3.12

python3 manage.py runserver