django – Heroku没有从requirements.txt安装psycopg2

解决了

在requirements.txt中,将gunicorn == 19.0.0更改为gunicorn == 18.0.0,并且它完成了诀窍.版本19.0.0打破了Python 2.x,它阻止了psycopg2的安装.

原始问题

我在requirements.txt中有以下内容:

Django==1.6.5
South==0.8.4
argparse==1.2.1
dj-database-url==0.3.0
dj-static==0.0.5
django-toolbelt==0.0.1
gunicorn==19.0.0
psycopg2==2.5.2
pystache==0.5.4
static==1.0.2
wsgiref==0.1.2

但是当我推送到Heroku时,它没有安装psycopg2,甚至没有提到任何关于这种依赖的失败.

Initializing repository, done.
Counting objects: 1257, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1213/1213), done.
Writing objects: 100% (1257/1257), 504.62 KiB | 376.00 KiB/s, done.
Total 1257 (delta 642), reused 0 (delta 0)

-----> Python app detected
-----> Installing runtime (python-2.7.8)
-----> Installing dependencies with pip
       Downloading/unpacking Django==1.6.5 (from -r requirements.txt (line 1))
       Downloading/unpacking South==0.8.4 (from -r requirements.txt (line 2))
       Downloading/unpacking argparse==1.2.1 (from -r requirements.txt (line 3))
         Running setup.py (path:/tmp/pip_build_u3159/argparse/setup.py) egg_info for package argparse

           no previously-included directories found matching 'doc/_build'
           no previously-included directories found matching 'env24'
           no previously-included directories found matching 'env25'
           no previously-included directories found matching 'env26'
           no previously-included directories found matching 'env27'
       Downloading/unpacking dj-database-url==0.3.0 (from -r requirements.txt (line 4))
         Downloading dj_database_url-0.3.0-py2.py3-none-any.whl
       Downloading/unpacking dj-static==0.0.5 (from -r requirements.txt (line 5))
         Downloading dj-static-0.0.5.tar.gz
         Running setup.py (path:/tmp/pip_build_u3159/dj-static/setup.py) egg_info for package dj-static

       Downloading/unpacking gunicorn==19.0.0 (from -r requirements.txt (line 6))
         Running setup.py (path:/tmp/pip_build_u3159/gunicorn/setup.py) egg_info for package gunicorn

       Downloading/unpacking pystache==0.5.4 (from -r requirements.txt (line 7))
         Running setup.py (path:/tmp/pip_build_u3159/pystache/setup.py) egg_info for package pystache
           pystache: using: version '5.4.1' of <module 'setuptools' from '/app/.heroku/python/lib/python2.7/site-packages/setuptools-5.4.1-py2.7.egg/setuptools/__init__.pyc'>

       Downloading/unpacking static==1.0.2 (from -r requirements.txt (line 8))
         Downloading static-1.0.2.tar.gz
         Running setup.py (path:/tmp/pip_build_u3159/static/setup.py) egg_info for package static

       Installing collected packages: Django, South, argparse, dj-database-url, dj-static, gunicorn, pystache, static
         Running setup.py install for argparse

           no previously-included directories found matching 'doc/_build'
           no previously-included directories found matching 'env24'
           no previously-included directories found matching 'env25'
           no previously-included directories found matching 'env26'
           no previously-included directories found matching 'env27'
         Running setup.py install for dj-static

         Running setup.py install for gunicorn

             File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/gaiohttp.py", line 67
               yield from self.wsgi.close()
                        ^
           SyntaxError: invalid syntax

           Installing gunicorn_paster script to /app/.heroku/python/bin
           Installing gunicorn script to /app/.heroku/python/bin
           Installing gunicorn_django script to /app/.heroku/python/bin
         Running setup.py install for pystache
           pystache: using: version '5.4.1' of <module 'setuptools' from '/app/.heroku/python/lib/python2.7/site-packages/setuptools-5.4.1-py2.7.egg/setuptools/__init__.pyc'>

           Installing pystache script to /app/.heroku/python/bin
           Installing pystache-test script to /app/.heroku/python/bin
         Running setup.py install for static

           Installing static script to /app/.heroku/python/bin
       Successfully installed Django South argparse dj-database-url dj-static gunicorn pystache static
       Cleaning up...

-----> Preparing static assets
       Collectstatic configuration error. To debug, run:
       $heroku run python ./manage.py collectstatic --noinput

-----> Discovering process types
       Procfile declares types -> web

-----> Compressing... done, 34.7MB
-----> Launching... done, v5

当我尝试同步数据库时,它当然抱怨没有安装psycopg2.
如何让Heroku安装缺少的依赖项?我非常感谢任何有建设性的想法.

我的数据库设置,如果有问题的话:

DATABASES = {}
if ENV_TYPE == 'development':
    DATABASES['default'] = {'ENGINE': 'django.db.backends.sqlite3',
                            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),}
else:
    DATABASES['default'] = dj_database_url.config()

更新

对于gunicorn,报告中提到了一个SyntaxError.是否可能制动psycopg2的安装?我认为不应该.

最佳答案 Python 3.3中添加的产量.

File "/app/.heroku/python/lib/**python2.7**/site-packages/gunicorn/workers/gaiohttp.py"‌​, line 67 
  yield from self.wsgi.close()
点赞