【问题标题】:Trying to deploy to heroku but keep getting rejected试图部署到heroku,但一直被拒绝
【发布时间】:2016-07-17 22:45:04
【问题描述】:

我正在尝试在 heroku 上进行部署,这似乎是我自编程以来处理过的最复杂的问题。我收到一个错误,我没有 Procfile,但我有。它只命名为 Procfile。不是 ProcFile 或 Procfile.txt。跑完之后

 git push heroku master

我收到以下错误

 Counting objects: 8524, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (7522/7522), done.
    Writing objects: 100% (8524/8524), 14.00 MiB | 2.67 MiB/s, done.
    Total 8524 (delta 2214), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Python app detected
    remote:  !     Warning: Your application is missing a Procfile. This file tells Heroku how to run your application.
    remote:  !     Learn more: https://devcenter.heroku.com/articles/procfile
    remote: -----> Installing python-2.7.11
    remote:      $ pip install -r requirements.txt
    remote:        Collecting beautifulsoup4==4.4.1 (from -r requirements.txt (line 1))
    remote:          Downloading beautifulsoup4-4.4.1-py2-none-any.whl (81kB)
    remote:        Collecting dj-database-url==0.4.0 (from -r requirements.txt (line 2))
    remote:          Downloading dj-database-url-0.4.0.tar.gz
    remote:        Collecting dj-static==0.0.6 (from -r requirements.txt (line 3))
    remote:          Downloading dj-static-0.0.6.tar.gz
    remote:        Collecting Django==1.9.4 (from -r requirements.txt (line 4))
    remote:          Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
    remote:        Collecting django-crispy-forms==1.6.0 (from -r requirements.txt (line 5))
    remote:          Downloading django_crispy_forms-1.6.0-py2-none-any.whl (178kB)
    remote:        Collecting django-haystack==2.4.1 (from -r requirements.txt (line 6))
    remote:          Downloading django_haystack-2.4.1-py2-none-any.whl (95kB)
    remote:        Collecting django-taggit==0.18.0 (from -r requirements.txt (line 7))
    remote:          Downloading django_taggit-0.18.0-py2.py3-none-any.whl
    remote:        Collecting django-toolbelt==0.0.1 (from -r requirements.txt (line 8))
    remote:          Downloading django-toolbelt-0.0.1.tar.gz
    remote:        Collecting gunicorn==19.4.5 (from -r requirements.txt (line 9))
    remote:          Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
    remote:        Collecting Pillow==3.1.1 (from -r requirements.txt (line 10))
    remote:          Downloading Pillow-3.1.1.tar.gz (10.1MB)
    remote:        Collecting psycopg2==2.6.1 (from -r requirements.txt (line 11))
    remote:          Downloading psycopg2-2.6.1.tar.gz (371kB)
    remote:        Collecting pysolr==3.4.0 (from -r requirements.txt (line 12))
    remote:          Downloading pysolr-3.4.0-py2.py3-none-any.whl
    remote:        Collecting pytz==2016.1 (from -r requirements.txt (line 13))
    remote:          Downloading pytz-2016.1-py2.py3-none-any.whl (476kB)
    remote:        Collecting requests==2.9.1 (from -r requirements.txt (line 14))
    remote:          Downloading requests-2.9.1-py2.py3-none-any.whl (501kB)
    remote:        Collecting static3==0.6.1 (from -r requirements.txt (line 15))
    remote:          Downloading static3-0.6.1.tar.gz
    remote:        Collecting whitenoise==3.0 (from -r requirements.txt (line 16))
    remote:          Downloading whitenoise-3.0-py2.py3-none-any.whl
    remote:        Installing collected packages: beautifulsoup4, dj-database-url, static3, dj-static, Django, django-crispy-forms, django-haystack, django-taggit, psycopg2, gunicorn, django-toolbelt, Pillow, requests, pysolr, pytz, whitenoise
    remote:          Running setup.py install for dj-database-url: started
    remote:            Running setup.py install for dj-database-url: finished with status 'done'
    remote:          Running setup.py install for static3: started
    remote:            Running setup.py install for static3: finished with status 'done'
    remote:          Running setup.py install for dj-static: started
    remote:            Running setup.py install for dj-static: finished with status 'done'
    remote:          Running setup.py install for psycopg2: started
    remote:            Running setup.py install for psycopg2: finished with status 'done'
    remote:          Running setup.py install for django-toolbelt: started
    remote:            Running setup.py install for django-toolbelt: finished with status 'done'
    remote:          Running setup.py install for Pillow: started
    remote:            Running setup.py install for Pillow: finished with status 'done'
    remote:        Successfully installed Django-1.9.4 Pillow-3.1.1 beautifulsoup4-4.4.1 dj-database-url-0.4.0 dj-static-0.0.6 django-crispy-forms-1.6.0 django-haystack-2.4.1 django-taggit-0.18.0 django-toolbelt-0.0.1 gunicorn-19.4.5 psycopg2-2.6.1 pysolr-3.4.0 pytz-2016.1 requests-2.9.1 static3-0.6.1 whitenoise-3.0
    remote: 
    remote:      $ python mysite/manage.py collectstatic --noinput
    remote:        Traceback (most recent call last):
    remote:          File "mysite/manage.py", line 10, in <module>
    remote:            execute_from_command_line(sys.argv)
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    remote:            utility.execute()
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    remote:            self.execute(*args, **cmd_options)
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    remote:            output = self.handle(*args, **options)
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    remote:            collected = self.collect()
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
    remote:            for path, storage in finder.list(self.ignore_patterns):
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
    remote:            for path in utils.get_files(storage, ignore_patterns):
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    remote:            directories, files = storage.listdir(location)
    remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 299, in listdir
    remote:            for entry in os.listdir(path):
    remote:        OSError: [Errno 2] No such file or directory: '/app/mysite/mysite/static'
    remote: 
    remote:  !     Error while running '$ python mysite/manage.py collectstatic --noinput'.
    remote:        See traceback above for details.
    remote: 
    remote:        You may need to update application code to resolve this error.
    remote:        Or, you can disable collectstatic for this application:
    remote: 
    remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
    remote: 
    remote:        https://devcenter.heroku.com/articles/django-assets
    remote: 
    remote:  !     Push rejected, failed to compile Python app
    remote: 
    remote: Verifying deploy...
    remote: 
    remote: !       Push rejected to alt-vera.

我不知道问题是什么。我用谷歌搜索,似乎没有一个解决方案有效。另外,我在本地使用 python 3.5 但在我看到的错误消息中

 Installing python-2.7.11 Why is that. Could this be part of the error

编辑这是我的 Procfile

web: gunicorn mysite.wsgi:application --log-file -

编辑:在我一遍又一遍地做同样的事情之后它起作用了

但现在我收到了不同的错误消息

 OSError: [Errno 2] No such file or directory: '/app/mysite/mysite/static'
    remote: 
    remote:  !     Error while running '$ python mysite/manage.py collectstatic --noinput'.
    remote:        See traceback above for details.
    remote: 
    remote:        You may need to update application code to resolve this error.
    remote:        Or, you can disable collectstatic for this application:
    remote: 
    remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
    remote: 
    remote:        https://devcenter.heroku.com/articles/django-assets
    remote: 
    remote:  !     Push rejected, failed to compile Python app
    remote: 
    remote: Verifying deploy....
    remote: 
    remote: !       Push rejected to alt-vera.
    remote: 
    To https://git.heroku.com/alt-vera.git

【问题讨论】:

  • 你要收集静态资产吗?
  • 感谢您的回复。我只是尝试按照说明进行部署
  • 您需要创建一个配置文件(称为Profile),然后使用git add Procfile将其添加到您的存储库,然后提交您的更改git commit -m "adding procfile",最后,git push heroku master

标签: python git heroku


【解决方案1】:

您的应用程序缺少 procfile 添加它然后尝试。
求助https://devcenter.heroku.com/articles/procfile
Procfile 示例

web:python manage.py runserver
web: gunicorn your-app-name.wsgi --log-file -
heroku ps:scale web=1

【讨论】:

  • 感谢您的回复。我的 Procfile 与我的 requirements.txt 位于同一目录中。那是我的问题
  • @losee 这不是问题。我添加了 procfile 的示例看看。
  • 这仍然不起作用。我应该让 Procfile 结尾有句号吗?喜欢这个Procfile。我不明白为什么它没有读取我的 procfile
  • @losee 你是如何通过命令行或网站部署它的?
  • 通过命令行。我真的是束手无策。我已经删除了基于有关此主题的其他帖子使用触摸和回声创建的文件,但什么也没有。除了heroku之外还有什么更容易的吗?或者就部署而言,这一切都像这样吗?这太疯狂了
【解决方案2】:

来得比较晚,所以不确定这是否会有所帮助。我找到了你的问题,因为我遇到了同样的问题:我使用了 Heroku 提供的 Django 模板,并且在项目的根目录中肯定有一个 Procfile。

$ git init你在哪个文件夹里做了?

我的错误是我在桌面上创建了一个文件夹('WEB_CODE')来保存这个项目,并将这个文件夹初始化为一个 git repo。这意味着 Django 应用程序安装在 WEB_CODE/myapp 的子文件夹中,因此 Procfile 位于 myapp 的根目录中,而不是 git repo 的头部。

我放弃了这个并重新开始。我现在有一个新文件夹来保存所有内容(假设它被称为“APP_CODE”),一旦我安装了 Heroku 提供的 Django 应用程序,我将从此安装创建的子目录作为 git repo 的头(例如:APP_CODE/ myapp 是存储库,而不是 APP_CODE)。因此,Procfile 位于项目的根目录中。

我提交了更改,推送到了我的个人 github,然后我重新尝试了 $heroku create$ git push heroku master 命令,它们的效果非常好。

【讨论】:

    【解决方案3】:

    抱歉,如果迟到了,但我在谷歌搜索 2 小时后才发现它的答案 问题是我用小写p重命名了文件“procfile”。所以我用大写 P 将它重命名为“Procfile”。然后我重新创建了 git repo,然后将它们添加到阶段,然后提交它们。之后,我将我的分支“master”推到了heroku,它对我来说效果很好。

    我只是这样说,以防有人陷入同样的​​错误。

    【讨论】:

      【解决方案4】:

      我遇到了这个令人沮丧的问题,但我终于让我的 procfile 工作了。首先确保将其命名为“Procfile”,而不使用“.exe”或“.txt”或“.bat”。只是“Procfile”。对于 Django,我在 Procfile 中的每一行中都包含了以下内容:

      web:python manage.py runserver 
      web: gunicorn app-name.wsgi  
      heroku ps:scale web=1
      

      那么即使你之前已经这样做了,你也需要使用 cmd cd 到你的项目所在的文件中,然后输入以下命令并在每个命令之后点击:

      pip freeze > requirements.txt
      git init
      git add .
      git status
      git commit -m "Initial Commit"
      git push heroku master
      heroku open
      

      这对我有用。

      【讨论】:

        【解决方案5】:

        我刚遇到这个问题,使用命令创建 Procfile,而不是通过重命名创建的文件:

        echo web:..etc>Procfile       (without spaces)
        

        【讨论】:

          猜你喜欢
          • 2021-05-06
          • 1970-01-01
          • 2020-04-29
          • 1970-01-01
          • 2020-12-16
          • 1970-01-01
          • 1970-01-01
          • 2011-10-17
          • 2019-10-16
          相关资源
          最近更新 更多