Django ModuleNotFoundError: No module named 'settings'

Related searches
The Problem

When I try to run 'python manage.py runserver' I get this error:

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1068ddc80>
Traceback (most recent call last):
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/aricliesenfelt/.virtualenvs/django/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/aricliesenfelt/Desktop/scratch/django/django_tutorials/supplyai/ingest/models.py", line 5, in <module>
    import settings.py
ModuleNotFoundError: No module named 'settings'

Here is my urls.py:

from django.conf.urls import url, include
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^ingest/', include('ingest.urls'))
]

urlpatterns = format_suffix_patterns(urlpatterns)

Here is my models.py where I am just trying to import the local settings.py file I have. Not the main settings.py file, but the one I made locally for this app.

from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.engine.url import URL

import settings

DeclarativeBase = declarative_base()

def db_connect():
    return create_engine(URL(**settings.DATABASE))

def create_data_table(engine):
    DeclarativeBase.metadata.create_all(engine)

class Data(DeclarativeBase):
    __tablename__ = 'data'

    id = Column(Integer, primary_key=True)
    shipper_name = Column('shipper_name', String)
    seller_location = Column('seller_location', String)
    buyer_location = Column('buyer_location', String)
    product_category = Column('product_category', String)
    order_created_date = Column('order_created_date', String)

    def __init__(self, id, shipper_name, seller_location, buyer_location, product_category, order_created_date):
        self.id = id
        self.shipper_name = shipper_name
        self.seller_location = seller_location
        self.buyer_location = buyer_location
        self.product_category = product_category
        self.order_created_date = order_created_date

When I try to run the server, it is telling me that it cant find settings.py, but settings.py is literally in the same app that models.py is in. Not sure why this is happening. Any help would be GREATLY appreciated.

You will need to import it using the full path. Try

from ingest import settings

Django settings modules not found? ModuleNotFoundError, coverage run manage.py test --settings papersquirrel.settings.ci . But when I setup travis, I get an error: ModuleNotFoundError: No module named� I am trying to start up a very basic web app with Django and getting ModuleNotFoundError: No module named 'ui' My django project is frontend_project and the app is ui Tree: front_end ├── front-end/

Replace to import settings with from django.conf import settings

ModuleNotFoundError: No module named 'django.apps' � Issue , ModuleNotFoundError: No module named 'django.apps' #5794. Closed. hipertracker opened this issue on Jan 26 � 1 comment. Closed� The top level folder is not a Python module, it’s the one that contains the __init__.py that is. Therefore you want to import emailservice , without the prefix. krsanu555 April 3, 2020, 12:14pm

"""
Load Settings from django
"""
def setup_settings():
    import os
    import django

    # Connect to the Django Database
    script_path = os.path.dirname(__file__)
    os.environ['DJANGO_SETTINGS_MODULE']='<<YOUR_PROJECT>>.settings'
    django.setup()

def load_settings():

    from django.core.exceptions import ImproperlyConfigured

    try:
        from django.conf import settings as settings
        settings.BASE_DIR <<<< Try to access one your settings
    except (ImproperlyConfigured, ModuleNotFoundError) as ex:
        print("Settings not loaded yet.. Load it now.")
        setup_settings()
        from django.conf import settings as settings
        settings.BASE_DIR
        print("BASE_DIR (%s) loaded." % settings.BASE_DIR)
    except Exception as ex:
        print("Could not load settings (%s)" % ex)

    if not hasattr(settings, 'BASE_DIR'):
        print("Could not find BASE_DIR in settings! ERROR!")
        sys.exit(1)

    return settings

Than in every file you just call this two lines:

import load_settings
settings = load_settings()

ModuleNotFoundError: No module named 'django_project' when I , ModuleNotFoundError: No module named 'django_project' when I used When trying to run test for my django project using coverage run� 1.The name of the module is incorrect. The first reason for this error is the name of the module is incorrect, so you have to check out it 2.The path of the module is incorrect. Probably you would want to import a module file, but this module is not in the same directory.

ModuleNotFoundError: No module named 'django', If you got the error “ModuleNotFoundError: No module named 'django'” it means that Python couldn't find your Django package. Here's the full error message: Traceback (most recent call last): File "manage.py", line 10, in main from django. core. Well, I resolved it myself. Polls module was not found because it was created outside the project directory. When I removed it and recreated inside the project directory, it was OK now.

Browse other questions tagged python django django-debug-toolbar or ask your own question. The Overflow Blog The Loop, August 2020: Community-a-thon

"ModuleNotFoundError: No module named 'rest_framework'" It will ask you to import the given package, that is rest_framework and run the code again. This worked for me and trying to solve that error for a couple of days.

Comments
  • Try using from supplyai.ingest import settings