有谁能告诉我出了什么问题?
Heroku总是拒绝代码推送,因为它无法构建我的代码。从错误消息看,当它尝试使用pip安装requirement.txt时,似乎没有安装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'
答案 0 :(得分:0)
尝试以下方法。
1.确保已安装Ruby,然后从终端运行:
wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
2.登录heroku
$ heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password (typing will be hidden):
Authentication successful.
3.如果您尚未创建
,请创建您的应用$ cd ~/myapp
$ heroku create <app name>
4.install git
&amp;项目文件夹中的git init
5.登录到heroku仪表板获取你的应用程序git存储库
6。git remote add heroku <repository url>
7.在项目中进行更改并提交
8.在项目根文件夹中创建Procfile
web:python manage.py runserver
web: gunicorn <project-name>.wsgi --log-file -
heroku ps:scale web=1
9.在项目根文件夹中创建requirements.txt
文件
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.在settings.py
中,在文件末尾添加以下内容。
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.在wsgi.py
中添加以下内容到服务器静态文件
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())
12.提交您的更改并git push heroku master
。
现在,打开浏览器并输入https://your-app-name.heroku.com
,看看魔术。
答案 1 :(得分:0)
我自己解决了问题。解决方案是在错误消息&#34;需求解析错误&#34;之后。我发现新更新的requirements.txt文件中存在语法错误。通过纠正,问题就消失了。
遗憾的是,用户似乎无法直接看到错误的原因。希望我的共同故事可以导航将来陷入同样麻烦的编码人员。