在heroku上部署dash应用程序时,如何修复psycopg2 python库的ImportError?

2024-10-03 04:36:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Heroku上部署一个dash应用程序。我正在使用pyscopg2从Postgres导入数据。我尝试使用versions 2.8.6 and 2.7.5。当我在本地机器上使用这两个版本运行应用程序时,它可以正常工作。现在,他们每个人都有问题

2.8.6一起:

该应用程序部署在Heroku上,但不运行。当我尝试在本地运行它时,会显示以下错误

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

第2.7.5节:

应用程序无法部署。当我运行git push heroku master时。我得到以下错误

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'

我试过以下方法:

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

我正在使用python版本3.7.3,我也在使用virtualenvironment


Tags: installpippygitapp应用程序herokuremote