hanadasouta
@hanadasouta (うた そ)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

ModuleNotFoundError: No module named 'app.settings' について

ModuleNotFoundError: No module named 'blogapp.settings'のエラーで
collectstaticができません。

エラーの解決策、または可能性のある原因のご教授をお願い致します。

エラーが出力したときのコマンドは、
python manage.py collectstatic また、
python manage.py makemigrations でも同様の結果になりました。

かれこれ一か月ほど試行錯誤を繰り返していますが、自分の知識では突破できないと思いました。
環境:python3.6.8 , django3.0.8 centos7

ochikobore.
├─blogapp
│  ├─migrations
│  │  └─__pycache__
│  ┣─__pycache__
│  ┣─__init__.py
│  ┣─admin.py
│  ┣─apps.py
│  ┣─forms.py
│  ┣─models.py
│  ┣─tests.py
│  ┣─urls.py
│  └─views.py
├─blogproject
│  ┣─__pycache__
│  ┣─__init__.py
│  ┣─asgi.py
│  ┣─settings.py
│  ┣─urls.py
│  └-wsgi.py
├─static
│  ┣─style.css
│  └─reset.css
├─staticfiles
│  ├─admin
│  │  ├─css
│  │  │  └─vendor
│  │  │      └─select2
│  │  ├─fonts
│  │  ├─img
│  │  │  └─gis
│  │  └─js
│  │      ├─admin
│  │      └─vendor
│  │          ├─jquery
│  │          ├─select2
│  │          │  └─i18n
│  │          └─xregexp
│  └─media_root
│      ├─post_content_images
│      └─post_images
└─templates
errorcode.rb
Traceback (most recent call last):
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/base.py", line 366, in execute
    self.check()
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/base.py", line 395, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/checks/translation.py", line 52, in check_setting_languages_bidi
    for tag in settings.LANGUAGES_BIDI if not isinstance(tag, str) or not language_code_re.match(tag)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'blogapp.settings'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/core/management/base.py", line 341, in run_from_argv
    connections.close_all()
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/db/utils.py", line 225, in close_all
    for alias in self:
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/db/utils.py", line 219, in __iter__
    return iter(self.databases)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/db/utils.py", line 153, in databases
    self._databases = settings.DATABASES
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/hanadasouta/ochikobore/ochikoboreenv/lib64/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'blogapp.settings'

エラーの解決策、または可能性のある対応策のご教授をよろしくお願いします。。。。。

0

2Answer

見づらいのでコードブロックを利用してください。
あと、settings.pyががあるディレクトリはどこですか?
エラーになったコマンドを正確に教えてください(引数付きかどうかも必要なため)

0Like

Comments

  1. @hanadasouta

    Questioner

    ご指摘と返答ありがとうございます!

    settings.py は blogproject に入っています。

    エラーが出力したときのコマンドは、
    python manage.py collectstatic です。
    また、python manage.py makemigrations でも同様の結果になりました。

以下のような記述になっていませんか?

blogproject/wsgi.py
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogapp.settings")

その場合は以下のように修正してください。

blogproject/wsgi.py
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogproject.settings")

startproject 後にsettings.pyが入っているディレクトリ名を変更した場合に発生するようです。

0Like

Comments

  1. @hanadasouta

    Questioner

    ご返答ありがとうございます!

    wsgi.pyを確認したところblogproject.settingsとなっておりました。

    同様にasgi.pyとmanage.pyも調べてみましたが、
    どちらもblogproject.settingsでした。

Your answer might help someone💌