Heroku部署-ModuleNotFoundError:运行'$ python manage.py collectstatic --noinput'时没有名为'eventshow.local_settings'的模块出错

时间:2020-03-17 18:36:45

标签: python django python-3.x git heroku

尝试在Heroku上部署Django-Postgres应用时遇到以下问题:

>❯git push heroku master
Enumerating objects: 246, done.
Counting objects: 100% (246/246), done.
Delta compression using up to 4 threads
Compressing objects: 100% (108/108), done.
Writing objects: 100% (246/246), 4.87 MiB | 1.62 MiB/s, done.
Total 246 (delta 114), reused 239 (delta 112)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip
remote:        Collecting asgiref==3.2.3
remote:          Downloading asgiref-3.2.3-py2.py3-none-any.whl (18 kB)
remote:        Collecting astroid==2.3.3
remote:          Downloading astroid-2.3.3-py3-none-any.whl (205 kB)
remote:        Collecting autopep8==1.5
remote:          Downloading autopep8-1.5.tar.gz (116 kB)
remote:        Collecting dj-database-url==0.5.0
remote:          Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
remote:        Collecting Django==3.0.4
remote:          Downloading Django-3.0.4-py3-none-any.whl (7.5 MB)
remote:        Collecting django-extensions==2.2.8
remote:          Downloading django_extensions-2.2.8-py2.py3-none-any.whl (224 kB)
remote:        Collecting django-heroku==0.3.1
remote:          Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
remote:        Collecting djangorestframework==3.11.0
remote:          Downloading djangorestframework-3.11.0-py3-none-any.whl (911 kB)
remote:        Collecting Faker==4.0.1
remote:          Downloading Faker-4.0.1-py3-none-any.whl (994 kB)
remote:        Collecting gunicorn==20.0.4
remote:          Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
remote:        Collecting isort==4.3.21
remote:          Downloading isort-4.3.21-py2.py3-none-any.whl (42 kB)
remote:        Collecting lazy-object-proxy==1.4.3
remote:          Downloading lazy_object_proxy-1.4.3-cp36-cp36m-manylinux1_x86_64.whl (55 kB)
remote:        Collecting mccabe==0.6.1
remote:          Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
remote:        Collecting Pillow==7.0.0
remote:          Downloading Pillow-7.0.0-cp36-cp36m-manylinux1_x86_64.whl (2.1 MB)
remote:        Collecting psycopg2==2.8.4
remote:          Downloading psycopg2-2.8.4.tar.gz (377 kB)
remote:        Collecting pycodestyle==2.5.0
remote:          Downloading pycodestyle-2.5.0-py2.py3-none-any.whl (51 kB)
remote:        Collecting pylint==2.4.4
remote:          Downloading pylint-2.4.4-py3-none-any.whl (302 kB)
remote:        Collecting python-dateutil==2.8.1
remote:          Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
remote:        Collecting pytz==2019.3
remote:          Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
remote:        Collecting six==1.14.0
remote:          Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
remote:        Collecting sqlparse==0.3.1
remote:          Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
remote:        Collecting text-unidecode==1.3
remote:          Downloading text_unidecode-1.3-py2.py3-none-any.whl (78 kB)
remote:        Collecting whitenoise==5.0.1
remote:          Downloading whitenoise-5.0.1-py2.py3-none-any.whl (20 kB)
remote:        Collecting wrapt==1.11.2
remote:          Downloading wrapt-1.11.2.tar.gz (27 kB)
remote:        Collecting typed-ast<1.5,>=1.4.0; implementation_name == "cpython" and python_version < "3.8"
remote:          Downloading typed_ast-1.4.1-cp36-cp36m-manylinux1_x86_64.whl (737 kB)
remote:        Building wheels for collected packages: autopep8, psycopg2, wrapt
remote:          Building wheel for autopep8 (setup.py): started
remote:          Building wheel for autopep8 (setup.py): finished with status 'done'
remote:          Created wheel for autopep8: filename=autopep8-1.5-py2.py3-none-any.whl size=43266 sha256=eca9268c40b02ba94b2b9933b8e3e44be2615890dccb7ebde18e89f0493c8c37
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-q7cw7463/wheels/64/f9/3a/5f9703ee48b111e6d9c9a6be6fb351285e607775127015afa2
remote:          Building wheel for psycopg2 (setup.py): started
remote:          Building wheel for psycopg2 (setup.py): finished with status 'done'
remote:          Created wheel for psycopg2: filename=psycopg2-2.8.4-cp36-cp36m-linux_x86_64.whl size=446449 sha256=be78f893d3721a444dbf20918f46fcfb079e9b34260eaf22a9ccc1ce73e7c582
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-q7cw7463/wheels/1e/cb/03/20479d63812e4a01da92afa8753f6ad37f87806c24a620aaa0
remote:          Building wheel for wrapt (setup.py): started
remote:          Building wheel for wrapt (setup.py): finished with status 'done'
remote:          Created wheel for wrapt: filename=wrapt-1.11.2-cp36-cp36m-linux_x86_64.whl size=69773 sha256=a4021a9ff0177e308b57724eb209086cf2e7ab5befb930d3c17c84cb22025b57
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-q7cw7463/wheels/0d/85/48/15d7bfab92a2d0e87372224c1f628fc57db7447a663a58e86c
remote:        Successfully built autopep8 psycopg2 wrapt
remote:        Installing collected packages: asgiref, lazy-object-proxy, six, typed-ast, wrapt, astroid, pycodestyle, autopep8, dj-database-url, sqlparse, pytz, Django, django-extensions, psycopg2, whitenoise, django-heroku, djangorestframework, python-dateutil, text-unidecode, Faker, gunicorn, isort, mccabe, Pillow, pylint
remote:        Successfully installed Django-3.0.4 Faker-4.0.1 Pillow-7.0.0 asgiref-3.2.3 astroid-2.3.3 autopep8-1.5 dj-database-url-0.5.0 django-extensions-2.2.8 django-heroku-0.3.1 djangorestframework-3.11.0 gunicorn-20.0.4 isort-4.3.21 lazy-object-proxy-1.4.3 mccabe-0.6.1 psycopg2-2.8.4 pycodestyle-2.5.0 pylint-2.4.4 python-dateutil-2.8.1 pytz-2019.3 six-1.14.0 sqlparse-0.3.1 text-unidecode-1.3 typed-ast-1.4.1 whitenoise-5.0.1 wrapt-1.11.2
remote: 
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 224, in fetch_command
remote:            app_name = commands[subcommand]
remote:        KeyError: 'collectstatic'
remote:        During handling of the above exception, another exception occurred:
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 21, in <module>
remote:            main()
remote:          File "manage.py", line 17, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 231, in fetch_command
remote:            settings.INSTALLED_APPS
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
remote:            self._setup(name)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
remote:            self._wrapped = Settings(settings_module)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
remote:            mod = importlib.import_module(self.SETTINGS_MODULE)
remote:          File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 994, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 971, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
remote:        ModuleNotFoundError: No module named 'eventshow.release_settings'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.

我看到的最相关的部分如下:

$ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 224, in fetch_command
remote:            app_name = commands[subcommand]
remote:        KeyError: 'collectstatic'
remote:        During handling of the above exception, another exception occurred:
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 21, in <module>
remote:            main()
remote:          File "manage.py", line 17, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 231, in fetch_command
remote:            settings.INSTALLED_APPS
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
remote:            self._setup(name)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
remote:            self._wrapped = Settings(settings_module)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
remote:            mod = importlib.import_module(self.SETTINGS_MODULE)
remote:          File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 994, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 971, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
remote:        ModuleNotFoundError: No module named 'eventshow.release_settings'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.

使用上面的跟踪信息,我一直在寻找解决方案,但没有找到任何有用的方法。这是我的配置文件:

  • Procfile:web: gunicorn --pythonpath eventshow/eventshow eventshow.wsgi --log-file -。我已经使用了上面的一个,也:web: gunicorn eventshow.wsgi --log-file -

  • requirements.txt:

    asgiref==3.2.3
    astroid==2.3.3
    autopep8==1.5
    certifi==2019.11.28
    chardet==3.0.4
    dj-database-url==0.5.0
    Django==3.0.4
    django-extensions==2.2.8
    django-heroku==0.3.1
    Faker==4.0.1
    googlemaps==4.2.0
    gunicorn==20.0.4
    idna==2.9
    isort==4.3.21
    lazy-object-proxy==1.4.3
    mccabe==0.6.1
    Pillow==7.0.0
    psycopg2==2.8.4
    pycodestyle==2.5.0
    pylint==2.4.4
    pyparsing==2.4.6
    python-dateutil==2.8.1
    pytz==2019.3
    requests==2.23.0
    six==1.14.0
    sqlparse==0.3.1
    text-unidecode==1.3
    urllib3==1.25.8
    whitenoise==5.0.1
    wrapt==1.11.2
  • wsgi.py:
    import os

    from django.core.wsgi import get_wsgi_application

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eventshow.release_settings')

    application = get_wsgi_application()
  • release_settings.py:
    import os
    import dj_database_url
    import django_heroku
    from decouple import config


    """
    Django settings for eventshow project.

    Generated by 'django-admin startproject' using Django 2.2.7.

    For more information on this file, see
    https://docs.djangoproject.com/en/2.2/topics/settings/

    For the full list of settings and their values, see
    https://docs.djangoproject.com/en/2.2/ref/settings/
    """


    # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


    # Quick-start development settings - unsuitable for production
    # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

    # SECURITY WARNING: keep the secret key used in production secret!
    SECRET_KEY = ''

    # SECURITY WARNING: don't run with debug turned on in production!
    DEBUG = False

    ALLOWED_HOSTS = ['*']


    # Application definition

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        # Our installed apps
        'main',
        'django_extensions'
    ]

    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        'whitenoise.middleware.WhiteNoiseMiddleware',
    ]

    ROOT_URLCONF = 'eventshow.urls'

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'templates')],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]

    WSGI_APPLICATION = 'eventshow.wsgi.application'


    # Database
    # https://docs.djangoproject.com/en/2.2/ref/settings/#databases


    DATABASES = {
        'default': dj_database_url.config(
            default=config('DATABASE_URL')
        )
    }


    # Password validation
    # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]

    AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'main.backends.EmailAuthBackend'
    )
    # Internationalization
    # https://docs.djangoproject.com/en/2.2/topics/i18n/

    LANGUAGE_CODE = 'en-us'

    TIME_ZONE = 'UTC'

    USE_I18N = True

    USE_L10N = True

    USE_TZ = True


    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/2.2/howto/static-files/

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

    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )
    STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
    STATIC_URL = '/static/'

    LOGIN_REDIRECT_URL = '/'
    LOGOUT_REDIRECT_URL = '/'

    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

    django_heroku.settings(locals())

在此问题上,我将提供一些帮助。谢谢!

0 个答案:

没有答案