Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django no module name 'config'

Tags:

python

django

I wrote these apps using Python 2 and now am using Python 3.

I've tried:

  1. Changing to a new virtualenv and reinstalling requirements
  2. pip install config -> returns a new Syntax error in an Exception...
  3. pip install django-config

When running: python3 manage.py runserver I keep getting the following error:

Traceback (most recent call last):
      File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
      File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
      File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 308, in execute
settings.INSTALLED_APPS
      File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
      File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
      File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/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 941, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      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 'config'
like image 970
edank Avatar asked Jan 22 '18 06:01

edank


2 Answers

I had this same problem and to get it to work I had to set the DJANGO_SETTINGS_MODULE environment variable to be the path to my settings.py file

export DJANGO_SETTINGS_MODULE=project_name.settings

like image 125
Four_0h_Three Avatar answered Oct 11 '22 14:10

Four_0h_Three


I did something similar to @PetarP:

INSTALLED_APPS = [
    # user-defined
    'blog.apps.BlogConfig',

    # default
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles', 
    # no 'django.contrib.sites'
]

as you can find this at /blog/apps.py:

from django.apps import AppConfig
class BlogConfig(AppConfig):
    name = 'blog'
like image 25
ehacinom Avatar answered Oct 11 '22 13:10

ehacinom