I have a dash application that I want to deploy on Heroku. I am using pyscopg2
to import data from Postgres. I tried using versions 2.8.6 and 2.7.5
. The app works properly when I run it on my local machine with both these versions. Now, here's the problem with each of them.
With 2.8.6
:
The app gets deployed on Heroku but doesn't run. When I try to run it locally it shows the following error
Traceback (most recent call last):
File "/Users/nikhilsawal/OneDrive/investment-portfolio-app/eda.py", line 2, in <module>
import psycopg2
File "/Users/nikhilsawal/OneDrive/investment-portfolio-app/app_env/lib/python3.7/site-packages/psycopg2/__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ImportError: dlopen(/Users/nikhilsawal/OneDrive/investment-portfolio-app/app_env/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libssl.1.1.dylib
Referenced from: /Users/nikhilsawal/OneDrive/investment-portfolio-app/app_env/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
Reason: image not found
With 2.7.5:
The app fails to deploy. When I run git push heroku master
. I get the following error
ERROR: Failed building wheel for psycopg2
error: command '/usr/bin/gcc' failed with exit code 1
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-125s5nei/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-125s5nei/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-kygc7a2a/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.9/psycopg2 Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to investment-application.
remote:
To https://git.heroku.com/investment-application.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/investment-application.git'
I tried the following things:
pip install psycopg2-binary
- Psycopg2 image not found
- Broken references in Virtualenvs
I am using python version 3.7.3
and I'm also using virtualenvironment
.