error during deploying django project to heruku

Issue

I am trying to deplow a django project to heroku but i am getting this error.

ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python /app/.heroku/python/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp5mrz1adn Check the logs for full command output.
! Push rejected, failed to compile Python app.
! Push failed

This is the entire log

ctivity Feed  Build LogID 314cb820-4652-417b-9486-61d629e4a6a9
-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/python
-----> Python app detected
-----> Using Python version specified in runtime.txt
-----> Installing python-3.8.12
-----> Installing pip 20.2.4, setuptools 57.5.0 and wheel 0.37.0
-----> Installing SQLite3
-----> Installing requirements with pip
       Collecting alembic==1.6.5
         Downloading alembic-1.6.5-py2.py3-none-any.whl (164 kB)
       Collecting asgiref==3.3.4
         Downloading asgiref-3.3.4-py3-none-any.whl (22 kB)
       Collecting Babel==2.9.1
         Downloading Babel-2.9.1-py2.py3-none-any.whl (8.8 MB)
       Collecting bcrypt==3.2.0
         Downloading bcrypt-3.2.0-cp36-abi3-manylinux2010_x86_64.whl (63 kB)
       Collecting bidict==0.21.2
         Downloading bidict-0.21.2-py2.py3-none-any.whl (37 kB)
       Collecting blinker==1.4
         Downloading blinker-1.4.tar.gz (111 kB)
       Collecting Brotli==1.0.9
         Downloading Brotli-1.0.9-cp38-cp38-manylinux1_x86_64.whl (357 kB)
       Collecting cffi==1.14.6
         Downloading cffi-1.14.6-cp38-cp38-manylinux1_x86_64.whl (411 kB)
       Collecting cheroot==8.5.2
         Downloading cheroot-8.5.2-py2.py3-none-any.whl (97 kB)
       Collecting click==7.1.2
         Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
       Collecting cryptography==3.4.7
         Downloading cryptography-3.4.7-cp36-abi3-manylinux2014_x86_64.whl (3.2 MB)
       Collecting Django==3.2.8
         Downloading Django-3.2.8-py3-none-any.whl (7.9 MB)
       Collecting django-ckeditor==6.1.0
         Downloading django_ckeditor-6.1.0-py2.py3-none-any.whl (2.4 MB)
       Collecting django-filter==2.4.0
         Downloading django_filter-2.4.0-py3-none-any.whl (73 kB)
       Collecting django-js-asset==1.2.2
         Downloading django_js_asset-1.2.2-py2.py3-none-any.whl (5.8 kB)
       Collecting django-multiselectfield==0.1.12
         Downloading django_multiselectfield-0.1.12-py3-none-any.whl (15 kB)
       Collecting dnspython==1.16.0
         Downloading dnspython-1.16.0-py2.py3-none-any.whl (188 kB)
       Collecting email-validator==1.1.3
         Downloading email_validator-1.1.3-py2.py3-none-any.whl (18 kB)
       Collecting eventlet==0.31.0
         Downloading eventlet-0.31.0-py2.py3-none-any.whl (224 kB)
       Collecting Flask==1.1.4
         Downloading Flask-1.1.4-py2.py3-none-any.whl (94 kB)
       Collecting Flask-BabelEx==0.9.4
         Downloading Flask_BabelEx-0.9.4-py3-none-any.whl (8.7 kB)
       Collecting Flask-Compress==1.10.1
         Downloading Flask_Compress-1.10.1-py3-none-any.whl (7.9 kB)
       Collecting Flask-Gravatar==0.5.0
         Downloading Flask_Gravatar-0.5.0-py2.py3-none-any.whl (7.5 kB)
       Collecting Flask-Login==0.5.0
         Downloading Flask_Login-0.5.0-py2.py3-none-any.whl (16 kB)
       Collecting Flask-Mail==0.9.1
         Downloading Flask-Mail-0.9.1.tar.gz (45 kB)
       Collecting Flask-Migrate==2.7.0
         Downloading Flask_Migrate-2.7.0-py2.py3-none-any.whl (13 kB)
       Collecting Flask-Paranoid==0.2.0
         Downloading Flask_Paranoid-0.2.0-py2.py3-none-any.whl (4.1 kB)
       Collecting Flask-Principal==0.4.0
         Downloading Flask-Principal-0.4.0.tar.gz (5.5 kB)
       Collecting Flask-Security-Too==4.0.1
         Downloading Flask_Security_Too-4.0.1-py2.py3-none-any.whl (244 kB)
       Collecting Flask-SocketIO==5.1.0
         Downloading Flask_SocketIO-5.1.0-py2.py3-none-any.whl (16 kB)
       Collecting Flask-SQLAlchemy==2.5.1
         Downloading Flask_SQLAlchemy-2.5.1-py2.py3-none-any.whl (17 kB)
       Collecting Flask-WTF==0.15.1
         Downloading Flask_WTF-0.15.1-py2.py3-none-any.whl (13 kB)
       Collecting greenlet==1.1.0
         Downloading greenlet-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (164 kB)
       Collecting gunicorn==20.1.0
         Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
       Collecting httpagentparser==1.9.1
         Downloading httpagentparser-1.9.1.tar.gz (7.9 kB)
       Collecting idna==3.2
         Downloading idna-3.2-py3-none-any.whl (59 kB)
       Collecting importlib-resources==5.2.2
         Downloading importlib_resources-5.2.2-py3-none-any.whl (27 kB)
       Collecting itsdangerous==1.1.0
         Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
       Collecting jaraco.functools==3.3.0
         Downloading jaraco.functools-3.3.0-py3-none-any.whl (6.8 kB)
       Collecting Jinja2==2.11.3
         Downloading Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)
       Collecting ldap3==2.9
         Downloading ldap3-2.9-py2.py3-none-any.whl (430 kB)
       Collecting Mako==1.1.4
         Downloading Mako-1.1.4-py2.py3-none-any.whl (75 kB)
       Collecting MarkupSafe==2.0.1
         Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl (30 kB)
       Collecting more-itertools==8.8.0
         Downloading more_itertools-8.8.0-py3-none-any.whl (48 kB)
       Collecting paramiko==2.7.2
         Downloading paramiko-2.7.2-py2.py3-none-any.whl (206 kB)
       Collecting passlib==1.7.4
         Downloading passlib-1.7.4-py2.py3-none-any.whl (525 kB)
       Collecting pgadmin4==5.4
         Downloading pgadmin4-5.4-py3-none-any.whl (99.6 MB)
       Collecting Pillow==8.3.1
         Downloading Pillow-8.3.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (3.0 MB)
       Collecting postgres==4.0
         Downloading postgres-4.0-py2.py3-none-any.whl (21 kB)
       Collecting psutil==5.8.0
         Downloading psutil-5.8.0-cp38-cp38-manylinux2010_x86_64.whl (296 kB)
       Collecting psycopg2==2.9.1
         Downloading psycopg2-2.9.1.tar.gz (379 kB)
       Collecting psycopg2-binary==2.8.6
         Downloading psycopg2_binary-2.8.6-cp38-cp38-manylinux1_x86_64.whl (3.0 MB)
       Collecting psycopg2-pool==1.1
         Downloading psycopg2_pool-1.1-py2.py3-none-any.whl (7.3 kB)
       Collecting pyasn1==0.4.8
         Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
       Collecting pycparser==2.20
         Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
       Collecting PyNaCl==1.4.0
         Downloading PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl (961 kB)
       Collecting python-dateutil==2.8.1
         Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
       Collecting python-editor==1.0.4
         Downloading python_editor-1.0.4-py3-none-any.whl (4.9 kB)
       Collecting python-engineio==4.2.0
         Downloading python_engineio-4.2.0-py2.py3-none-any.whl (51 kB)
       Collecting python-socketio==5.3.0
         Downloading python_socketio-5.3.0-py2.py3-none-any.whl (53 kB)
       Collecting pytz==2021.1
         Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
       Collecting pywinpty==1.1.1
         Downloading pywinpty-1.1.1.tar.gz (48 kB)
         Installing build dependencies: started
         Installing build dependencies: finished with status 'done'
         Getting requirements to build wheel: started
         Getting requirements to build wheel: finished with status 'done'
           Preparing wheel metadata: started
           Preparing wheel metadata: finished with status 'error'
           ERROR: Command errored out with exit status 1:
            command: /app/.heroku/python/bin/python /app/.heroku/python/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp5mrz1adn
                cwd: /tmp/pip-install-19xig8s3/pywinpty
           Complete output (6 lines):
           Checking for Rust toolchain...
           
           Cargo, the Rust package manager, is not installed or is not on PATH.
           This package requires Rust and Cargo to compile extensions. Install it through
           the system's package manager or via https://rustup.rs/
           
           ----------------------------------------
       ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python /app/.heroku/python/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmp5mrz1adn Check the logs for full command output.
 !     Push rejected, failed to compile Python app.
 !     Push failed

my runtime.txt contains the python version 3.8.12 which is supported by heroku.

Please suggest me what should I do to resolve this error.

Solution

After carefully reading log file, here’s what I recommend to do for clean deploy.

While venv is activated and you’re in project directory (where manage.py live), do the following:

  • Open requirements.txt
  • Delete unneeded modules from requirements.txt
  • Uninstall unneeded modules with pip uninstall module
  • Now run pip freeze requirements.txt
  • Deactivate venv
  • Then add requirements.txt to source control git add -A
  • Commit your changes git commit -m "deleted unneeded modules"
  • If you have existed Heroku app, connect to it with
    heroku git:remote -a myapp, else pass this step
  • Deploy, git push heroku master

If you are unsure which modules your project need and I can’t determin exactly the project’s requirements but if you have basic project, you only need 3 modules which are Django, psycopg2-binary, gunicorn, so do the following for clean deploy:

  • Delete venv
  • Outside project directory, create new one
  • Activate venv
  • Install the modules you need, probably Django, psycopg2-binary, gunicorn
  • Now run pip freeze requirements.txt
  • Deactivate venv
  • Then add requirements.txt to source control git add -A
  • Commit your changes git commit -m "deleted unneeded modules"
  • If you have existed Heroku app, connect to it with
    heroku git:remote -a myapp, else pass this step
  • Deploy, git push heroku master

Answered By – HB21

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published