简体   繁体   中英

heroku rejected django app push

Could anyone suggest me what has been wrong?

The Heroku always reject code push because it can't build my code. From the error message it seems that the Pip is not installed when it tried to install requirement.txt with pip!

  git push staging feature/homepage:master
Counting objects: 16, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (16/16), 1.48 KiB | 0 bytes/s, done.
Total 16 (delta 9), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: Usage: pip-diff [options]
remote: 
remote: Traceback (most recent call last):
remote:   File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-pop/pip-diff", line 116, in <module>
remote:     main()
remote:   File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-pop/pip-diff", line 112, in main
remote:     diff(**kwargs)
remote:   File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-pop/pip-diff", line 84, in diff
remote:     r1 = Requirements(r1)
remote:   File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-pop/pip-diff", line 29, in __init__
remote:     self.load(reqfile)
remote:   File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pip-pop/pip-diff", line 39, in load
remote:     for requirement in parse_requirements(reqfile, finder=finder, session=requests):
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_file.py", line 93, in parse_requirements
remote:     for req in req_iter:
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_file.py", line 192, in process_line
remote:     for req in parser:
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_file.py", line 93, in parse_requirements
remote:     for req in req_iter:
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_file.py", line 140, in process_line
remote:     opts, _ = parser.parse_args(shlex.split(options_str), defaults)
remote:   File "/app/.heroku/python/lib/python2.7/optparse.py", line 1402, in parse_args
remote:     self.error(str(err))
remote:   File "/app/.heroku/python/lib/python2.7/optparse.py", line 1584, in error
remote:     self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_file.py", line 284, in parser_exit
remote:     raise RequirementsFileParseError(msg)
remote: pip.exceptions.RequirementsFileParseError: pip-diff: error: no such option: ------------------------
remote: 
remote:      $ pip install -r requirements.txt
remote:        Usage: pip [options]
remote:        
remote:        pip: error: no such option: ------------------------
remote:        
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to cryptic-forest-66390.
remote: 
To https://git.heroku.com/cryptic-forest-66390.git
 ! [remote rejected] feature/homepage -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cryptic-forest-66390.git'

try the following.

1.Ensure that you have Ruby installed, and then run this from your terminal:

wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh

2.Login to heroku

$ heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password (typing will be hidden):
Authentication successful.

3.Create your app if you haven't created

$ cd ~/myapp
$ heroku create <app name>

4.install git & git init in your project folder

5.login to heroku dashboard get your app git repository

6. git remote add heroku <repository url>

7.make your changes in project and commit

8.create Procfile in project root folder

web:python manage.py runserver
web: gunicorn <project-name>.wsgi --log-file -
heroku ps:scale web=1

9.Create requirements.txt file in project root folder

Django==1.9
gunicorn==19.4.5
psycopg2==2.6.1
whitenoise==2.0.6
wsgiref==0.1.2
dj-database-url==0.4.1

10.In your settings.py add the following at end of file.

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]
import dj_database_url

DATABASES['default'] = dj_database_url.config()

11.Add the following in wsgi.py to server static files

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())

12.Commit your changes and git push heroku master . Now, open your browser and type https://your-app-name.heroku.com see the magic.

Problem solved by myself. Solution was following the error message "requirement parse error". I found out there was a syntax error in newly updated requirement.txt file. By correcting that, the problem went away.

Shame that there seems no way an user could directly see what was exactly wrong. Hope my shared story could navigate coders who get into same trouble in future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM