ModuleNotFoundError:没有名为“< django_project_name>”Heroku deployment的模块

cbjzeqam  于 11个月前  发布在  Go
关注(0)|答案(1)|浏览(150)

在过去的2天里,我在网上看到了数十个关于同一主题的查询,但不幸的是,对我的情况没有任何帮助。我试图从windows 10部署在Heroku上。Python manage.py runserver在本地PC上工作正常,项目运行。
这是我的项目结构

austbooks
├── accounting
│   ├── admin.py
│   ├── apps.py
│   ├── forms.py
│   ├── migrations
│   ├── models.py
│   ├── static
│   │   └── accounting
│   │       ├── css
│   │       └── js
│   ├── templates
│   │   ├── account
│   │   └── accounting
│   ├── tests.py
│   ├── views.py
│   ├── __init__.py
│   └── __pycache__
├── austbooks
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
│   ├── __init__.py
│   └── __pycache__
├── manage.py
├── Procfile
├── requirements.txt
├── runtime.txt
└── staticfiles
    ├── Accounting
    │   ├── css
    │   └── js
    ├── admin
    │   ├── css
    │   ├── img
    │   └── js
    ├── debug_toolbar
    │   ├── css
    │   └── js
    └── staticfiles.json

字符串
我在部署到heroku时遇到以下错误

-----> $ python manage.py collectstatic --noinput
       Traceback (most recent call last):
         File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 255, in fetch_command
           app_name = commands[subcommand]
                      ~~~~~~~~^^^^^^^^^^^^
       KeyError: 'collectstatic'
       During handling of the above exception, another exception occurred:
       Traceback (most recent call last):
         File "/tmp/build_20b80918/manage.py", line 22, in <module>
           main()
         File "/tmp/build_20b80918/manage.py", line 18, in main
           execute_from_command_line(sys.argv)
         File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
           utility.execute()
         File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
           self.fetch_command(subcommand).run_from_argv(self.argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 262, in fetch_command
           settings.INSTALLED_APPS
         File "/app/.heroku/python/lib/python3.12/site-packages/django/conf/__init__.py", line 89, in __getattr__
           self._setup(name)
         File "/app/.heroku/python/lib/python3.12/site-packages/django/conf/__init__.py", line 76, in _setup
           self._wrapped = Settings(settings_module)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.12/site-packages/django/conf/__init__.py", line 190, in __init__
           mod = importlib.import_module(self.SETTINGS_MODULE)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         File "/app/.heroku/python/lib/python3.12/importlib/__init__.py", line 90, in import_module
           return _bootstrap._gcd_import(name[level:], package, level)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
         File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
         File "<frozen importlib._bootstrap>", line 1304, in _find_and_load_unlocked
         File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
         File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
         File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
         File "<frozen importlib._bootstrap>", line 1318, in _find_and_load_unlocked
       ModuleNotFoundError: No module named 'austbooks'
 !     Error while running '$ python manage.py collectstatic --noinput'.
       See traceback above for details.
       You may need to update application code to resolve this error.
       Or, you can disable collectstatic for this application:
          $ heroku config:set DISABLE_COLLECTSTATIC=1
       https://devcenter.heroku.com/articles/django-assets
 !     Push rejected, failed to compile Python app.
 !     Push failed


我尝试了heroku config:set DISABLE_COLLECTSTATIC,这使我能够部署应用程序,但之后当我在heroku上打开应用程序时出现错误
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail
Heroku日志给出了几乎与上面相同的错误,所以我重置了DISABLE_COLLECTSTATIC。
这是我的Procfile

web: gunicorn austbooks.wsgi


这是我的requirements.txt文件

asgiref==3.7.2
beautifulsoup4==4.12.2
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==41.0.5
defusedxml==0.7.1
dj-database-url==2.1.0
Django==5.0
django-allauth==0.58.2
django-debug-toolbar==4.2.0
django-heroku==0.3.1
gunicorn==21.2.0
idna==3.4
oauthlib==3.2.2
packaging==23.2
psycopg2==2.9.9
pycparser==2.21
PyJWT==2.8.0
python3-openid==3.2.0
requests==2.31.0
requests-oauthlib==1.3.1
soupsieve==2.5
sqlparse==0.4.4
typing_extensions==4.8.0
tzdata==2023.3
urllib3==2.1.0
whitenoise==6.6.0


收集静态环境变量:

remote:        PYTHONUNBUFFERED=1
remote:        PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:
remote:        DEBUG_COLLECTSTATIC=1
remote:        BPLOG_PREFIX=buildpack.python
remote:        PWD=/tmp/build_625825b2
remote:        HOME=/app
remote:        LANG=en_US.UTF-8
remote:        SOURCE_VERSION=47244666b9f674b55aaa9f02a17d31ee4cde1eee
remote:        REQUEST_ID=a7ad9d00-2b14-3b0f-6b3b-4372bc7a2ed4
remote:        DJANGO_SETTINGS_MODULE=austbooks.settings
remote:        ENV_DIR=/tmp/d20231206-54-a74wvd
remote:        PYTHONPATH=.
remote:        CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
remote:        BIN_DIR=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin
remote:        LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
remote:        SHLVL=1
remote:        LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
remote:        PIP_NO_PYTHON_VERSION_WARNING=1
remote:        BUILDPACK_LOG_FILE=/dev/null
remote:        STACK=heroku-22
remote:        BUILD_DIR=/tmp/build_625825b2
remote:        CACHE_DIR=/tmp/codon/tmp/cache
remote:        PATH=/app/.heroku/python/bin:/app/.heroku/vendor/bin::/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/
remote:        EXPORT_PATH=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/../export
remote:        C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
remote:        DYNO=run.2122
remote:        PROFILE_PATH=/tmp/build_625825b2/.profile.d/python.sh
remote:        OLDPWD=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136
remote:        _=/usr/bin/env


runtime.txt python-3.12.0
这是从我的settings.py

from pathlib import Path
import os
import django_heroku
import dj_database_url

BASE_DIR = Path(__file__).resolve().parent.parent

IS_HEROKU_APP = "DYNO" in os.environ and not "CI" in os.environ

INSTALLED_APPS = [
    # Use WhiteNoise's runserver implementation instead of the Django default, for dev-prod parity.
    "whitenoise.runserver_nostatic",
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounting',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'debug_toolbar',
]

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',
    'allauth.account.middleware.AccountMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'austbooks.urls'

WSGI_APPLICATION = 'austbooks.wsgi.application'

AUTHENTICATION_BACKENDS = [
    'allauth.account.auth_backends.AuthenticationBackend',
    'allauth.account.auth_backends.ModelBackend',
]

STATIC_URL = 'static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'accounting', 'static'),
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Static root for Heroku
STATIC_ROOT = BASE_DIR / 'staticfiles'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Heroku: Update database configuration from $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Activate Django-Heroku.
django_heroku.settings(locals())


wsgi.py文件

import os
from django.core.wsgi import get_wsgi_application
from whitenoise import WhiteNoise

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'austbooks.austbooks.settings')

application = get_wsgi_application()
application = WhiteNoise(application)


我已经在wsgi.py上用os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'austbooks.austbooks.settings')尝试了web: gunicorn austbooks.wsgi --log-file -web: gunicorn --pythonpath GroomingService GroomingService.wsgi,但没有成功。
我也检查过了,似乎没有任何拼写或大小写问题。

t3irkdon

t3irkdon1#

经过3天的努力,终于解决了这个问题。实际上,我的django项目名为“AustBooks”,并将其与github同步。后来我将名称改为“austbooks”,将所有字母都改为小写,但令人惊讶的是,github没有更新大写字母,尽管提交了很多次,但仍然保留了“AustBooks”。
因此,将项目名称更改为其他名称,提交到github,然后更改回“austbooks”解决了这个问题。

相关问题