【问题标题】:Heroku fails to install psycopg2Heroku 无法安装 psycopg2
【发布时间】:2017-12-05 05:41:08
【问题描述】:

我正在尝试让 Heroku 从 requirements.txt 安装 psycopg2,其中包含:

falcon
gunicorn>=19.6.0
gevent>=0.13
ujson
SQLAlchemy
alembic
psycopg2

这会产生以下构建日志:

-----> Python app detected
-----> Installing requirements with pip
       Collecting psycopg2 (from -r /tmp/build_e719ee5ccc3230ba0e40249f52a032c8/j4k0bk-MealoApi-15a38366ac18133eb1495aa651a7cad5497101c3/requirements.txt (line 7))
         Downloading psycopg2-2.7.1.tar.gz (421kB)
       Installing collected packages: psycopg2
         Running setup.py install for psycopg2: started
           Running setup.py install for psycopg2: finished with status 'error'
           Complete output from command /app/.heroku/python/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-EVUXmv/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-iefE_6-record/install-record.txt --single-version-externally-managed --compile:
           running install
           running build
           running build_py
           creating build
           creating build/lib.linux-x86_64-2.7
           creating build/lib.linux-x86_64-2.7/psycopg2
           copying lib/tz.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/psycopg1.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/__init__.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/extensions.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/_json.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/_range.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/extras.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/errorcodes.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/pool.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/sql.py -> build/lib.linux-x86_64-2.7/psycopg2
           copying lib/_ipaddress.py -> build/lib.linux-x86_64-2.7/psycopg2
           creating build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/testconfig.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_connection.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_fast_executemany.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_types_extras.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/dbapi20_tpc.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/testutils.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_psycopg2_dbapi20.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_bugX000.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/__init__.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_with.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/dbapi20.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_transaction.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_types_basic.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_module.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_async.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_copy.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_dates.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_green.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_extras_dictcursor.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_notify.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_async_keyword.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_lobject.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_bug_gc.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_quote.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_ipaddress.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_cancel.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_cursor.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_replication.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_errcodes.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           copying tests/test_sql.py -> build/lib.linux-x86_64-2.7/psycopg2/tests
           running build_ext
           building 'psycopg2._psycopg' extension
           creating build/temp.linux-x86_64-2.7
           creating build/temp.linux-x86_64-2.7/psycopg
           cc -O2 -fPIC -Wimplicit -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.7.1 (dt dec pq3 ext lo64)" -DPG_VERSION_NUM=90602 -DHAVE_LO64=1 -I/app/.heroku/python/include -I. -I/usr/include/postgresql -I/usr/include/postgresql/9.6/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-2.7/psycopg/psycopgmodule.o -Wdeclaration-after-statement
           In file included from psycopg/psycopgmodule.c:41:0:
           ./psycopg/error.h:32:5: error: unknown type name ‘PyBaseExceptionObject’
                PyBaseExceptionObject exc;
                ^
           error: command 'cc' failed with exit status 1

           ----------------------------------------
       Command "/app/.heroku/python/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-EVUXmv/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-iefE_6-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-EVUXmv/psycopg2/
 !     Push rejected, failed to compile Python app.
 !     Push failed

这似乎符合 Herokus 关于如何通过 Python 连接到 PostgreSQL 的指南 (https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python),但是我似乎无法找到解决此问题的方法。

【问题讨论】:

  • 你为什么使用两个数据库 SQLAlchemy 和 postgreSQL。在 requirements.txt 中只试用一个
  • @RajanChahan SQLAlchemy 是一个 ORM,它使用 psycopg2 连接到特定的数据库服务器(本例中为 pgsql)

标签: python python-2.7 heroku psycopg2 heroku-postgres


【解决方案1】:

所以问题是因为我使用的是 pypy-5.3.1 运行时。我将其更改为 python-2.7.13 并且可以正常工作。

【讨论】:

    【解决方案2】:

    删除

    psycopg2==2.7.*

    来自 requirements.txt

    添加

    psycopg2-二进制

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-23
      • 2018-04-29
      • 2021-11-06
      • 2020-07-05
      • 2020-05-17
      • 2019-11-30
      • 1970-01-01
      • 2014-12-07
      相关资源
      最近更新 更多