Push rejected, failed to compile Python app

Question:

I’m getting a rejected error when trying to deploy a Django app to Heroku. I looked at possible solutions here:

  1. Heroku push rejected, failed to compile Python/django app (Python 2.7)

  2. Error pushing Django project to Heroku

But neither worked for me.

This is my flow from initiating the push to heroku:

git push heroku master 
Initializing repository, done.
Counting objects: 7024, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5915/5915), done.
Writing objects: 100% (7024/7024), 8.77 MiB | 104 KiB/s, done.
Total 7024 (delta 2183), reused 0 (delta 0)

 -----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.6.
-----> Preparing Python runtime (python-2.7.6)
-----> Installing Setuptools (2.1)
-----> Installing Pip (1.5.4)
-----> Installing dependencies using Pip (1.5.4)
     Downloading/unpacking Django==1.6.2 (from -r requirements.txt (line 1))
     Downloading/unpacking argparse==1.2.1 (from -r requirements.txt (line 2))
       argparse an externally hosted file and may be unreliable
       Running setup.py (path:/tmp/pip_build_u16439/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 distribute==0.6.24 (from -r requirements.txt (line 3))
       Running setup.py (path:/tmp/pip_build_u16439/distribute/setup.py) egg_info for package distribute

         warning: no files found matching 'Makefile' under directory 'docs'
         warning: no files found matching 'indexsidebar.html' under directory 'docs'
     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_u16439/dj-static/setup.py) egg_info for package dj-static

     Downloading/unpacking django-toolbelt==0.0.1 (from -r requirements.txt (line 6))
       Downloading django-toolbelt-0.0.1.tar.gz
       Running setup.py (path:/tmp/pip_build_u16439/django-toolbelt/setup.py) egg_info for package django-toolbelt

     Downloading/unpacking gunicorn==18.0 (from -r requirements.txt (line 7))
       Running setup.py (path:/tmp/pip_build_u16439/gunicorn/setup.py) egg_info for package gunicorn

     Downloading/unpacking psycopg2==2.5.2 (from -r requirements.txt (line 8))
       Running setup.py (path:/tmp/pip_build_u16439/psycopg2/setup.py) egg_info for package psycopg2

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

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

     Installing collected packages: Django, argparse, distribute, dj-database-url, dj-static, django-toolbelt, gunicorn, psycopg2, 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 distribute
         Before install bootstrap.
         Scanning installed packages
         Setuptools installation detected at /app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg
         Egg installation
         Patching...
         Renaming /app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg into /app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg.OLD.1397160440.32
         Patched done.
         Relaunching...
         Traceback (most recent call last):
           File "<string>", line 1, in <module>
         NameError: name 'install' is not defined
         Complete output from command /app/.heroku/python/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_u16439/distribute/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record /tmp/pip-7JPdSe-record/install-record.txt --single-version-externally-managed --compile:
         Before install bootstrap.

     Scanning installed packages

     Setuptools installation detected at /app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg

     Egg installation

     Patching...

     Renaming /app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg into /app/.heroku/python/lib/python2.7/site-packages/setuptools-2.1-py2.7.egg.OLD.1397160440.32

     Patched done.

     Relaunching...

     Traceback (most recent call last):

       File "<string>", line 1, in <module>

     NameError: name 'install' is not defined

     ----------------------------------------
     Cleaning up...
     Command /app/.heroku/python/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_u16439/distribute/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record /tmp/pip-7JPdSe-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_u16439/distribute
     Storing debug log for failure in /app/.pip/pip.log

 !     Push rejected, failed to compile Python app

My requirements.txt

Django==1.6.2
argparse==1.2.1
distribute==0.6.24
dj-database-url==0.3.0
dj-static==0.0.5
django-toolbelt==0.0.1
gunicorn==18.0
psycopg2==2.5.2
pystache==0.5.3
static==1.0.2
wsgiref==0.1.2

Procfile

web: gunicorn app.wsgi

I’ve followed the instructions from the Heroku website. Any idea what I’m missing?

Asked By: Newtt

||

Answers:

This is apparently a bug in the distribute package, which doesn’t seem likely to get fixed:

Distribute is now considered deprecated and replaced by setuptools. I suggest replacing ‘distribute==0.6.28’ in requirements.txt with ‘setuptools==1.0’ or similar. The latest versions of pip (>=1.4) and setuptools (>=0.7) have better support for the unified code and upgrades and seek to obviate issues like the one encountered here.

Answered By: lanzz

This is a problem with the deprecated distribute package. See Bug #91 on Bitbucket.

Replacing distribute==0.6.24 with setuptools==0.7.3 in your requirements.txt file should remedy your problem.

Answered By: rnevius

I had this error until I upgraded the Heroku stack from cedar-14 (old and deprecated) to Heroku-18 (new). Then everything worked.

Answered By: Soferio

In runtime.txt file, any of these versions can be included:
python-3.10.6 on all supported stacks (recommended)
python-3.9.13 on all supported stacks
python-3.8.13 on Heroku-18 and Heroku-20 only
python-3.7.13 on Heroku-18 and Heroku-20 only

This will resolve your error.

Answered By: Leelavathi Rajan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.