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

cbjzeqam  于 2024-01-08  发布在  Go
关注(0)|答案(1)|浏览(248)

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

  1. austbooks
  2. ├── accounting
  3. ├── admin.py
  4. ├── apps.py
  5. ├── forms.py
  6. ├── migrations
  7. ├── models.py
  8. ├── static
  9. └── accounting
  10. ├── css
  11. └── js
  12. ├── templates
  13. ├── account
  14. └── accounting
  15. ├── tests.py
  16. ├── views.py
  17. ├── __init__.py
  18. └── __pycache__
  19. ├── austbooks
  20. ├── asgi.py
  21. ├── settings.py
  22. ├── urls.py
  23. ├── wsgi.py
  24. ├── __init__.py
  25. └── __pycache__
  26. ├── manage.py
  27. ├── Procfile
  28. ├── requirements.txt
  29. ├── runtime.txt
  30. └── staticfiles
  31. ├── Accounting
  32. ├── css
  33. └── js
  34. ├── admin
  35. ├── css
  36. ├── img
  37. └── js
  38. ├── debug_toolbar
  39. ├── css
  40. └── js
  41. └── staticfiles.json

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

  1. -----> $ python manage.py collectstatic --noinput
  2. Traceback (most recent call last):
  3. File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 255, in fetch_command
  4. app_name = commands[subcommand]
  5. ~~~~~~~~^^^^^^^^^^^^
  6. KeyError: 'collectstatic'
  7. During handling of the above exception, another exception occurred:
  8. Traceback (most recent call last):
  9. File "/tmp/build_20b80918/manage.py", line 22, in <module>
  10. main()
  11. File "/tmp/build_20b80918/manage.py", line 18, in main
  12. execute_from_command_line(sys.argv)
  13. File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
  14. utility.execute()
  15. File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
  16. self.fetch_command(subcommand).run_from_argv(self.argv)
  17. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  18. File "/app/.heroku/python/lib/python3.12/site-packages/django/core/management/__init__.py", line 262, in fetch_command
  19. settings.INSTALLED_APPS
  20. File "/app/.heroku/python/lib/python3.12/site-packages/django/conf/__init__.py", line 89, in __getattr__
  21. self._setup(name)
  22. File "/app/.heroku/python/lib/python3.12/site-packages/django/conf/__init__.py", line 76, in _setup
  23. self._wrapped = Settings(settings_module)
  24. ^^^^^^^^^^^^^^^^^^^^^^^^^
  25. File "/app/.heroku/python/lib/python3.12/site-packages/django/conf/__init__.py", line 190, in __init__
  26. mod = importlib.import_module(self.SETTINGS_MODULE)
  27. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  28. File "/app/.heroku/python/lib/python3.12/importlib/__init__.py", line 90, in import_module
  29. return _bootstrap._gcd_import(name[level:], package, level)
  30. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  31. File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
  32. File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
  33. File "<frozen importlib._bootstrap>", line 1304, in _find_and_load_unlocked
  34. File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  35. File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
  36. File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
  37. File "<frozen importlib._bootstrap>", line 1318, in _find_and_load_unlocked
  38. ModuleNotFoundError: No module named 'austbooks'
  39. ! Error while running '$ python manage.py collectstatic --noinput'.
  40. See traceback above for details.
  41. You may need to update application code to resolve this error.
  42. Or, you can disable collectstatic for this application:
  43. $ heroku config:set DISABLE_COLLECTSTATIC=1
  44. https://devcenter.heroku.com/articles/django-assets
  45. ! Push rejected, failed to compile Python app.
  46. ! 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

  1. web: gunicorn austbooks.wsgi


这是我的requirements.txt文件

  1. asgiref==3.7.2
  2. beautifulsoup4==4.12.2
  3. certifi==2023.7.22
  4. cffi==1.16.0
  5. charset-normalizer==3.3.2
  6. cryptography==41.0.5
  7. defusedxml==0.7.1
  8. dj-database-url==2.1.0
  9. Django==5.0
  10. django-allauth==0.58.2
  11. django-debug-toolbar==4.2.0
  12. django-heroku==0.3.1
  13. gunicorn==21.2.0
  14. idna==3.4
  15. oauthlib==3.2.2
  16. packaging==23.2
  17. psycopg2==2.9.9
  18. pycparser==2.21
  19. PyJWT==2.8.0
  20. python3-openid==3.2.0
  21. requests==2.31.0
  22. requests-oauthlib==1.3.1
  23. soupsieve==2.5
  24. sqlparse==0.4.4
  25. typing_extensions==4.8.0
  26. tzdata==2023.3
  27. urllib3==2.1.0
  28. whitenoise==6.6.0


收集静态环境变量:

  1. remote: PYTHONUNBUFFERED=1
  2. remote: PKG_CONFIG_PATH=/app/.heroku/vendor/lib/pkg-config:/app/.heroku/python/lib/pkg-config:
  3. remote: DEBUG_COLLECTSTATIC=1
  4. remote: BPLOG_PREFIX=buildpack.python
  5. remote: PWD=/tmp/build_625825b2
  6. remote: HOME=/app
  7. remote: LANG=en_US.UTF-8
  8. remote: SOURCE_VERSION=47244666b9f674b55aaa9f02a17d31ee4cde1eee
  9. remote: REQUEST_ID=a7ad9d00-2b14-3b0f-6b3b-4372bc7a2ed4
  10. remote: DJANGO_SETTINGS_MODULE=austbooks.settings
  11. remote: ENV_DIR=/tmp/d20231206-54-a74wvd
  12. remote: PYTHONPATH=.
  13. remote: CPLUS_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
  14. remote: BIN_DIR=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin
  15. remote: LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
  16. remote: SHLVL=1
  17. remote: LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/.heroku/python/lib:
  18. remote: PIP_NO_PYTHON_VERSION_WARNING=1
  19. remote: BUILDPACK_LOG_FILE=/dev/null
  20. remote: STACK=heroku-22
  21. remote: BUILD_DIR=/tmp/build_625825b2
  22. remote: CACHE_DIR=/tmp/codon/tmp/cache
  23. 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/
  24. remote: EXPORT_PATH=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/../export
  25. remote: C_INCLUDE_PATH=/app/.heroku/vendor/include:/app/.heroku/python/include:
  26. remote: DYNO=run.2122
  27. remote: PROFILE_PATH=/tmp/build_625825b2/.profile.d/python.sh
  28. remote: OLDPWD=/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136
  29. remote: _=/usr/bin/env


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

  1. from pathlib import Path
  2. import os
  3. import django_heroku
  4. import dj_database_url
  5. BASE_DIR = Path(__file__).resolve().parent.parent
  6. IS_HEROKU_APP = "DYNO" in os.environ and not "CI" in os.environ
  7. INSTALLED_APPS = [
  8. # Use WhiteNoise's runserver implementation instead of the Django default, for dev-prod parity.
  9. "whitenoise.runserver_nostatic",
  10. 'django.contrib.admin',
  11. 'django.contrib.auth',
  12. 'django.contrib.contenttypes',
  13. 'django.contrib.sessions',
  14. 'django.contrib.messages',
  15. 'django.contrib.staticfiles',
  16. 'accounting',
  17. 'allauth',
  18. 'allauth.account',
  19. 'allauth.socialaccount',
  20. 'debug_toolbar',
  21. ]
  22. MIDDLEWARE = [
  23. 'django.middleware.security.SecurityMiddleware',
  24. 'django.contrib.sessions.middleware.SessionMiddleware',
  25. 'django.middleware.common.CommonMiddleware',
  26. 'django.middleware.csrf.CsrfViewMiddleware',
  27. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  28. 'django.contrib.messages.middleware.MessageMiddleware',
  29. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  30. 'allauth.account.middleware.AccountMiddleware',
  31. 'debug_toolbar.middleware.DebugToolbarMiddleware',
  32. 'whitenoise.middleware.WhiteNoiseMiddleware',
  33. ]
  34. ROOT_URLCONF = 'austbooks.urls'
  35. WSGI_APPLICATION = 'austbooks.wsgi.application'
  36. AUTHENTICATION_BACKENDS = [
  37. 'allauth.account.auth_backends.AuthenticationBackend',
  38. 'allauth.account.auth_backends.ModelBackend',
  39. ]
  40. STATIC_URL = 'static/'
  41. STATICFILES_DIRS = (
  42. os.path.join(BASE_DIR, 'accounting', 'static'),
  43. )
  44. STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  45. # Static root for Heroku
  46. STATIC_ROOT = BASE_DIR / 'staticfiles'
  47. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  48. # Heroku: Update database configuration from $DATABASE_URL.
  49. db_from_env = dj_database_url.config(conn_max_age=500)
  50. DATABASES['default'].update(db_from_env)
  51. # Activate Django-Heroku.
  52. django_heroku.settings(locals())


wsgi.py文件

  1. import os
  2. from django.core.wsgi import get_wsgi_application
  3. from whitenoise import WhiteNoise
  4. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'austbooks.austbooks.settings')
  5. application = get_wsgi_application()
  6. 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”解决了这个问题。

相关问题