#Psyopg2[binary] not working

72 messages · Page 1 of 1 (latest)

fleet olive
#

For some reason psycopg[binary] has stopped working. Is there some workaround for this?

I have tried uninstalling it and installing it.

I have checked stack overflow and they tell me to install different ways. I have tried that and it hasn't worked.

Stack Overflow: https://stackoverflow.com/questions/8237842/django-core-exceptions-improperlyconfigured-error-loading-psycopg-module-no-mo

Has something updated?

Error message and pip list output
https://paste.pythondiscord.com/7WRQ
Stack Overflow
django.core.exceptions.ImproperlyConfigured: Error loading psycopg ...
Presently, I'm attempting to configure Django for use on a project, and am encountering a persistent error when I try to run python manage.py syncdb.

File "/x/x/x/x/x/x/base.py", line 23, in ?
...

analog cypress
fleet olive
#

Django updated!? Ahhhhh thats why

analog cypress
#

Consider storing your package versions in a requirements.txt file and pinning the versions

That way you have a reproducible setup :)

fleet olive
#

Package Version


asgiref 3.7.2
Django 5.0
pip 23.3.2
setuptools 65.5.0
sqlparse 0.4.4
typing_extensions 4.9.0
(.venv) andrewstribling@Andrews-MBP ch4-bookstore %

#

pinning the versions?

#

so I install psycopg[binary] correct?

#

I seem to still be getting the error when i do psycopg[binary]

analog cypress
fleet olive
analog cypress
#

Oh wait, you updated django to 5, alright then, yea
pip install psycopg[binary] will suffice

#

(Make sure you reactivated your env, when you recreated it)

fleet olive
#

i have to restart my enviornment?

analog cypress
#

venv*
Virtual environment

Just close the terminal and reopen, or run "deactivate" followed by "export /.venv/bin/activate"

fleet olive
#

attempting

#

grrrr I am still having an error for some reason

#

one sec let me export

analog cypress
#

Can you send the traceback?

fleet olive
#

yes one moment

#

Thank you for assisting me by the way

#

psyopg[binary]==YOUR_VERSION_NUMBER what do you mean by that

analog cypress
#

Interesting, hmm

#

in your DATABASES section

fleet olive
#

checking

#

postgress

analog cypress
#

ehrm

#

DATABASES = DATABASES = {
On line 77

#

That should probably only be DATABASES = {

#

(Although it shouldn't be causing the problem you have)

fleet olive
#

fixed

#

how can I tell if my virtual enviornment has it?

#

pip list correct?

analog cypress
#

I'd recommend deleting your venv folder and creating a new one, maybe thats the problem

analog cypress
fleet olive
#

maybe my interpreter is targeting the wrong enviornment?

analog cypress
#

That lists all installed packages that the current interpreter has access to (well, not quite, just the ones that pip found, but you're not using other package managers, so yes)

fleet olive
#

if I uninstall django and psycopg

#

than deactivate my enviornment

analog cypress
fleet olive
#

so just try deleting the venv folder and try again

analog cypress
#

Inbetween creating the new venv and installing the packages you should probably close your terminal

#

(or call "deactivate")

fleet olive
#

attempting

#

attempting

#

WHY DOES IT PERSIST!?

analog cypress
#

Are you on windows?
I've had some wonky behavior with psycopg on windows in the past

fleet olive
#

macbook

analog cypress
#

Alright then, hmm

fleet olive
#

should I github push this

analog cypress
#

try and create an empty dummy project with a new, fresh virtual environment

Lets see if its something in your project

fleet olive
analog cypress
fleet olive
#

you have helped me many times before and I thank you for it JaK

#

(project_env) andrewstribling@Andrews-MBP ch4-bookstore % docker-compose exec web python3 manage.py startapp accounts

versed spoke
#

What's your database engine?

#

I have seen few blogs where people have used postgresql_psycopg as engine, not just postgresql, specially with psycopg binary

#
    "default": {
        "ENGINE": "django.db.backends.postgresql", # try postgresql_psycopg
        "NAME": "postgres",
        "USER": "postgres",
        "PASSWORD": "postgres",
        "HOST": "db", # this should be loclahost if you're running on local machine
        "PORT": 5432,
    }
}```
#

Another point to note when using virtual environment with VS Code is, always check that your venv is selected as interpreter, and then kill all terminal and reopen.

You terminal should be something like
(venv) path

#

Though these were the only issues I've faced given the context, since you're running your project in docker, it may have a different reason.

#

I have no experience with docker yet.

analog cypress
# fleet olive I have re pushed the files

I've just noticed, you're running the debian slim docker image, the slim version is not recommended in scenarios where you aren't incredibly storage bound.

Try it out with the normal debian one and lets see if that changes things (i don't even know what debian slim is missing in comparison - probably some binaries like nano)

#

I'd put money on that being the problem

Also, your engine "django.db.backends.postgresql" was totally fine, leave it at that.
The django 4.2 release notes even state that specifically.
https://docs.djangoproject.com/en/5.0/releases/4.2/#what-s-new-in-django-4-2

you don’t need to change the ENGINE as django.db.backends.postgresql supports both libraries.

Also, your HOST setting for the database was also totally correct, as long as your database container is actually called "db"

analog cypress
# versed spoke ```DATABASES = DATABASES = { "default": { "ENGINE": "django.db.backe...

Just as a quick explanation why "db" is set as the hostname:
If you have a docker network, your containers can refer to each other by name.
Docker will inject the docker network ip addresses of the containers with their container name in any other containers hosts file

You wouldn't want to use localhost, as there could be other containers running on the same system, using the same port, you specifically want the container named "db" (That might also not be exposing its port to the host's network)

versed spoke
#

I see, so that's how it is. Thanks for the explanation, I'll start learning Docker soon.

fleet olive
#

Is there a way to understand how each part of the docker file works and know what is acceptable and is not?