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.4Building 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 pippython3 -m pip install --upgrade setuptoolspython3 -m pip install -r requirements.txtpython3 -m pip uninstall -y psycopgpython3 -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 foundDuring 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 DatabaseModuleNotFoundError: No module named 'psycopg2'The only thing that works for me is specifying this in requirements.txt:
psycopg2-binary~=2.9.3But:
- I don't want to use the older psycopg 2
- I want to evaluate my app on two providers, and changing
requirements.txtwill "downgrade"psycopgon both.