Setup: Django, Python
A discussion from 2022 suggests a workaround which worked for me, basically to pin to an older version psycopg2
binary.
However, it’s 2025 and I’d like to use the more modern psycopg3
with Django. I’m currently evaluating vercel vs Railway, and have this in my requirements.txt
file:
psycopg==3.2.4
Building this fails on vercel. I tried doing this at the beginning of my buildfiles.sh
script:
echo "Step 7: Installing Python dependencies"
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade setuptools
python3 -m pip install -r requirements.txt
python3 -m pip uninstall -y psycopg
python3 -m pip install "psycopg[binary]"
But it still fails with this appearing in the logs:
No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/task/django/db/backends/postgresql/base.py", line 27, in <module>
import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'
The only thing that works for me is specifying this in requirements.txt
:
psycopg2-binary~=2.9.3
But:
- I don’t want to use the older psycopg 2
- I want to evaluate my app on two providers, and changing
requirements.txt
will “downgrade”psycopg
on both.