Can't connect Conda Psycopg in Django, only system-level python works

46 Views Asked by At

I have wanted to switch from using the system-level python packages (arch-linux) to mamba/conda virtual env.

Note that postgresql.service is running fine system level.

I have installed all the same packages in the virtual environment. It works perfect on main system python but fails in conda. I even set env-variables in zsh shell for postgresql and done chmod 0600 ~/.my_pgpass

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "OPTIONS": {
            "service": "my_service", // location - /home/zane/.pg_service.conf
            "passfile": ".my_pgpass", //location is project root
            "server_side_binding": True,
        },
    }
}

Without conda virtual env:(works fine)

python manage.py migrate  

Operations to perform:
  Apply all migrations: admin, auth, business, contenttypes, sessions
Running migrations:
  No migrations to apply.
**(All runs fine without virtual enviroment)**

with conda virtual env-

mamba activate django
(django) 
Django-CRUD main 
 ❯ python manage.py migrate
   Traceback (most recent call last):
   django.db.utils.OperationalError: connection is bad: No such file or directory
        Is the server running locally and accepting connections on that socket?

I have also inserted zsh shell variables

  export PGPASSFILE="/home/zane/projects/Django-CRUD/.my_pgpass" 
  export PGSYSCONFDIR=/home/zane/
  export PGSERVICEFILE=/home/zane/.pg_service.conf

Please help as none of the above worked

0

There are 0 best solutions below