Heroku无法安装psycopg2

时间:2017-07-01 11:30:15

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

我正在尝试让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(https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-python)连接到PostgreSQL的指南,但是我似乎找不到解决这个问题的方法。

2 个答案:

答案 0 :(得分:1)

所以问题是因为我使用的是 pypy-5.3.1 运行时。我把它更改为 python-2.7.13 ,它可以工作。

答案 1 :(得分:0)

删除

psycopg2 == 2.7。*

from requirements.txt

添加

psycopg2-binary