尝试将我的应用程序推送到 heroku 时出现此错误 FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstar

Posted

技术标签:

【中文标题】尝试将我的应用程序推送到 heroku 时出现此错误 FileNotFoundError: [Errno 2] No such file or directory: \'/app/gettingstarted/media\'【英文标题】:Trying to push my app to heroku gives me this error FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media'尝试将我的应用程序推送到 heroku 时出现此错误 FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media' 【发布时间】:2016-07-26 07:40:27 【问题描述】:

在尝试推送我的应用时出现以下错误

FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media'

但它确实存在让我感到困惑。导致它的文件结构是这样的

src/gettingstarted/媒体

媒体是一个空目录。昨晚我的推力还在工作。这是我运行 git push heroku master 的结果

Counting objects: 13, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (12/12), done.
    Writing objects: 100% (13/13), 670.50 KiB | 0 bytes/s, done.
    Total 13 (delta 9), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Using set buildpack heroku/python
    remote: -----> Python app detected
    remote:      $ pip install -r requirements.txt
    remote: 
    remote:      $ python manage.py collectstatic --noinput
    remote:        Traceback (most recent call last):
    remote:          File "manage.py", line 10, in <module>
    remote:            execute_from_command_line(sys.argv)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    remote:            utility.execute()
    remote:          File "/app/.heroku/python/lib/python3.5/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/python3.5/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/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    remote:            output = self.handle(*args, **options)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    remote:            collected = self.collect()
    remote:          File "/app/.heroku/python/lib/python3.5/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/python3.5/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/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    remote:            directories, files = storage.listdir(location)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/files/storage.py", line 299, in listdir
    remote:            for entry in os.listdir(path):
    remote:        FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media'
    remote: 
    remote:  !     Error while running '$ python 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 hispanicheights.
    remote: 
    To https://git.heroku.com/hispanicheights.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'https://git.heroku.com/hispanicheights.git'

在阅读了这里的帖子后,我运行了这个

 heroku config:set DEBUG_COLLECTSTATIC=1

得到以下输出

        Setting config vars and restarting hispanicheights... done
    DEBUG_COLLECTSTATIC: 1
    (practice) apples-MacBook-Pro:src ray$ git push heroku master
    Counting objects: 13, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (12/12), done.
    Writing objects: 100% (13/13), 670.50 KiB | 0 bytes/s, done.
    Total 13 (delta 9), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Using set buildpack heroku/python
    remote: -----> Python app detected
    remote:      $ pip install -r requirements.txt
    remote: 
    remote:      $ python manage.py collectstatic --noinput
    remote:        Traceback (most recent call last):
    remote:          File "manage.py", line 10, in <module>
    remote:            execute_from_command_line(sys.argv)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    remote:            utility.execute()
    remote:          File "/app/.heroku/python/lib/python3.5/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/python3.5/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/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    remote:            output = self.handle(*args, **options)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    remote:            collected = self.collect()
    remote:          File "/app/.heroku/python/lib/python3.5/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/python3.5/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/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    remote:            directories, files = storage.listdir(location)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/files/storage.py", line 299, in listdir
    remote:            for entry in os.listdir(path):
    remote:        FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/media'
    remote: 
    remote:  !     Error while running '$ python 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: ****** Collectstatic environment variables:
    remote: 
    remote:        CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/vendor/include:/app/.heroku/python/include:
    remote:        SOURCE_VERSION=68adc8ed3bbefc420568ec683846e0c2c2a51908
    remote:        PROFILE_PATH=/app/.profile.d/python.sh
    remote:        DEBUG_COLLECTSTATIC=1
    remote:        LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/vendor/lib:/app/.heroku/python/lib:
    remote:        CACHE_DIR=/app/tmp/cache
    remote:        PYTHONUNBUFFERED=1
    remote:        PYHONHOME=/app/.heroku/python
    remote:        LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/vendor/lib:/app/.heroku/python/lib:
    remote:        BIN_DIR=/app/tmp/buildpacks/python/bin
    remote:        PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin::/usr/local/bin:/app/bin:/app/vendor/bundle/bin:/app/vendor/bundle/ruby/2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/tmp/codon/vendor/bin:/app/tmp/buildpacks/python/vendor/bpwatch:/app/tmp/buildpacks/python/vendor/pip-pop
    remote:        RECOMMENDED_PYTHON_VERSION=python-2.7.11
    remote:        C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/vendor/include:/app/.heroku/python/include:
    remote:        PWD=/app
    remote:        LOG_FILE=/tmp/fifo20160406-3-8wj7yc
    remote:        LANG=en_US.UTF-8
    remote:        STACK=cedar-14
    remote:        TIMES=2
    remote:        SHLVL=3
    remote:        REQUEST_ID=327705f8-1028-4375-912a-f6abb15a9cb4
    remote:        HOME=/app
    remote:        BPWATCH_STORE_PATH=/app/tmp/cache/bpwatch.json
    remote:        PYTHONPATH=/app/
    remote:        BUILD_DIR=/app
    remote:        WARNINGS_LOG=/tmp/tmp.EFU8JTKPZD
    remote:        USER_LOG_FILE=/tmp/fifo20160406-3-12ib9mh
    remote:        PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkgconfig:/app/.heroku/vendor/lib/pkgconfig:/app/.heroku/vendor/lib/pkg-config:/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:
    remote:        DATABASE_URL=postgres://vzeteghnhlwrjq:OABELzntZhcJwAIaqTlsI-mwWl@ec2-54-235-93-178.compute-1.amazonaws.com:5432/d230us01stas97
    remote:        _=/usr/bin/env
    remote: 
    remote:  !     Push rejected, failed to compile Python app
    remote: 
    remote: Verifying deploy...
    remote: 
    remote: !       Push rejected to hispanicheights.
    remote: 
    To https://git.heroku.com/hispanicheights.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'https://git.heroku.com/hispanicheights.git'

不太清楚发生了什么,因为我在 django 上大约有 4 个月的时间。任何帮助或指导将不胜感激

不确定白噪声是否导致此问题。我对此表示怀疑。但这是我的 settings.py 文件

    MIDDLEWARE_CLASSES = (
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        'django.middleware.security.SecurityMiddleware',
        'whitenoise.middleware.WhiteNoiseMiddleware',
    )

    ROOT_URLCONF = 'gettingstarted.urls'


        STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
    STATIC_URL = '/static/'

    MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media_cdn')
    MEDIA_URL = '/media/'

    # Extra places for collectstatic to find static files.
    STATICFILES_DIRS = (
        os.path.join(PROJECT_ROOT, 'static'),
        os.path.join(PROJECT_ROOT, 'media'),
    )

    # Simplified static file serving.
    # https://warehouse.python.org/project/whitenoise/
    STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

我的入门/urls.py

        urlpatterns = [
        url(r'^admin/', include(admin.site.urls)),
        url(r'^blog/', include('hello.urls', namespace='blog', app_name='blog')),
        url(r'^db', hello.views.db, name='db'),
        url(r'^', include('hello.urls')), # hello corresponds to the hello module in installed apps
    ]

    if settings.DEBUG:
        urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
        urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

【问题讨论】:

【参考方案1】:

我认为这里的问题是 git 不跟踪空目录,它们需要包含至少一个文件让 git “看到”它们,所以虽然你的 media 目录存在于本地,但它在 Heroku 上不存在.处理此问题的常用方法是在目录中创建一个名为 .keep 的空文件。

【讨论】:

就是这样。我添加了 .keep 文件。然后我将其删除以确保它不是侥幸它不起作用。我把它加回来,它工作。谢谢

以上是关于尝试将我的应用程序推送到 heroku 时出现此错误 FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstar的主要内容,如果未能解决你的问题,请参考以下文章

当我尝试将我的应用推送到 Heroku 时,我收到了以下回复:

如何将我的节点应用程序成功推送到Heroku?

为啥当我尝试将我的 Spring Boot 应用程序推送到 heroku 时它返回“致命错误编译:无效目标版本:11”

每当我尝试将我的 django 应用程序推送到 Heroku 时,我的日志文件中都会出现以下错误,请协助我应该如何解决它,

如何将我的 git repo 的一部分推送到 Heroku?

isBlank() 在本地工作,但是在推送到 heroku 时:找不到符号