0

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:

  1. pip install psycopg2-binary
  2. Psycopg2 image not found
  3. Broken references in Virtualenvs

I am using python version 3.7.3 and I'm also using virtualenvironment.

torek
  • 448,244
  • 59
  • 642
  • 775
  • This has nothing to do with Git. The error message you got from heroku directs you to look at some log files to figure out why the compilation failed; that would probably be the thing to do. – torek Apr 23 '21 at 02:24
  • @torek the problem is that if I start over the process from scratch in a different directory, it works fine locally, but the moment I deploy it, it fails on heroku as well as locally – Nikhil Sawal Apr 23 '21 at 12:32
  • Also, when I am developing the app, I am using python Version --3.7.3, but when I deploy the changes to heroku, I see heroku installing python version --3.9.4 – Nikhil Sawal Apr 23 '21 at 12:38
  • 1
    The Python versioning is a Heroku issue. Why it starts failing locally is probably a Python issue—definitely not a Git issue but worth investigating separately. Given that the error message mentions Darwin shared objects, it will probably matter whether you're using homebrew to install Python if you're on an M1 Mac, as the M1 architecture has messed with a lot of assumptions people were making. – torek Apr 23 '21 at 21:43
  • This worked!! https://stackoverflow.com/questions/34304833/failed-building-wheel-for-psycopg2-macosx-using-virtualenv-and-pip – Nikhil Sawal Apr 26 '21 at 01:00

0 Answers0