title: Django on Heroku: ModuleNotFoundError: No module named 'app_name'
body: <p>I've been having some trouble getting my Django app with the django rest framework to deploy without errors to heroku. The strange thing is, there would be no issues in pushing and deploying to Heroku but would crash after deployment. Here is my file structure:</p>
  
  <pre><code>Include/
  man/
  Procfile/
  requirements.txt
  runtime.txt
  Scripts/
  tcl/
  webadvisorapi
      │   manage.py
      ├───src
      │   │   admin.py
      │   │   apps.py
      │   │   models.py
      │   │   serializers.py
      │   │   tests.py
      │   │   urls.py
      │   │   views.py
      │   │   __init__.py
      │   │
      │   ├───management
      │   │   │   __init__.py
      │   │   │
      │   │   └───commands
      │   │           runrequest.py
      │   │           __init__.py
      │   │
      │   ├───scripts
      │           request.py
      │           __init__.py
      │
      ├───static
      │       .keep
      │
      ├───staticfiles
      └───webadvisorapi
          │   settings.py
          │   urls.py
          │   wsgi.py
          │   __init__.py
          │
          ├───static
          │       .keep
  </code></pre>
  
  <p>I have already ran this on my own machine and it worked just fine. Interestingly, my app could not be pushed and deployed to Heroku when I use any other path other than <code>src.apps.SrcConfig</code> in <code>INSTALLED_APPS</code> as it gives me the same ModuleNotFoundError. Besides that, I did get a successful deployment but the app crashed. I even cloned my project from heroku and ran my project locally and there was no issue. Here is the log from heroku logs --tail:</p>
  
  <pre><code>2019-07-13T06:43:31.172615+00:00 heroku[web.1]: Starting process with command `gunicorn webadvisorapi.webadvisorapi.wsgi --log-file -`
  2019-07-13T06:43:33.243340+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [4] [INFO] Starting gunicorn 19.9.0
  2019-07-13T06:43:33.243849+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [4] [INFO] Listening at: http://0.0.0.0:34512 (4)
  2019-07-13T06:43:33.243940+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [4] [INFO] Using worker: sync
  2019-07-13T06:43:33.249546+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [10] [INFO] Booting worker with pid: 10
  2019-07-13T06:43:33.350998+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [11] [INFO] Booting worker with pid: 11
  2019-07-13T06:43:33.524337+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [10] [ERROR] Exception in worker
  process
  2019-07-13T06:43:33.524355+00:00 app[web.1]: Traceback (most recent call last):
  2019-07-13T06:43:33.524394+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
  2019-07-13T06:43:33.524397+00:00 app[web.1]: worker.init_process()
  2019-07-13T06:43:33.524399+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
  2019-07-13T06:43:33.524401+00:00 app[web.1]: self.load_wsgi()
  2019-07-13T06:43:33.524403+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
  2019-07-13T06:43:33.524405+00:00 app[web.1]: self.wsgi = self.app.wsgi()
  2019-07-13T06:43:33.524413+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
  2019-07-13T06:43:33.524415+00:00 app[web.1]: self.callable = self.load()
  2019-07-13T06:43:33.524417+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
  2019-07-13T06:43:33.524419+00:00 app[web.1]: return self.load_wsgiapp()
  2019-07-13T06:43:33.524421+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
  2019-07-13T06:43:33.524423+00:00 app[web.1]: return util.import_app(self.app_uri)
  2019-07-13T06:43:33.524425+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
  2019-07-13T06:43:33.524426+00:00 app[web.1]: __import__(module)
  2019-07-13T06:43:33.524428+00:00 app[web.1]: File "/app/webadvisorapi/webadvisorapi/wsgi.py", line 17, in
  &lt;module&gt;
  2019-07-13T06:43:33.524430+00:00 app[web.1]: application = get_wsgi_application()
  2019-07-13T06:43:33.524432+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  2019-07-13T06:43:33.524434+00:00 app[web.1]: django.setup(set_prefix=False)
  2019-07-13T06:43:33.524436+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
  2019-07-13T06:43:33.524438+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
  2019-07-13T06:43:33.524440+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
  2019-07-13T06:43:33.524442+00:00 app[web.1]: app_config = AppConfig.create(entry)
  2019-07-13T06:43:33.524444+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
  2019-07-13T06:43:33.524445+00:00 app[web.1]: mod = import_module(mod_path)
  2019-07-13T06:43:33.524447+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
  2019-07-13T06:43:33.524454+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
  2019-07-13T06:43:33.524457+00:00 app[web.1]: ModuleNotFoundError: No module named 'src'
  2019-07-13T06:43:33.524572+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [10] [INFO] Worker exiting (pid:
  10)
  2019-07-13T06:43:33.676529+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [11] [ERROR] Exception in worker
  process
  2019-07-13T06:43:33.676532+00:00 app[web.1]: Traceback (most recent call last):
  2019-07-13T06:43:33.676535+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
  2019-07-13T06:43:33.676537+00:00 app[web.1]: worker.init_process()
  2019-07-13T06:43:33.676538+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
  2019-07-13T06:43:33.676540+00:00 app[web.1]: self.load_wsgi()
  2019-07-13T06:43:33.676541+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
  2019-07-13T06:43:33.676543+00:00 app[web.1]: self.wsgi = self.app.wsgi()
  2019-07-13T06:43:33.676545+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
  2019-07-13T06:43:33.676547+00:00 app[web.1]: self.callable = self.load()
  2019-07-13T06:43:33.676549+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
  2019-07-13T06:43:33.676550+00:00 app[web.1]: return self.load_wsgiapp()
  2019-07-13T06:43:33.676552+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
  2019-07-13T06:43:33.676553+00:00 app[web.1]: return util.import_app(self.app_uri)
  2019-07-13T06:43:33.676555+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
  2019-07-13T06:43:33.676556+00:00 app[web.1]: __import__(module)
  2019-07-13T06:43:33.676558+00:00 app[web.1]: File "/app/webadvisorapi/webadvisorapi/wsgi.py", line 17, in
  &lt;module&gt;
  2019-07-13T06:43:33.676559+00:00 app[web.1]: application = get_wsgi_application()
  2019-07-13T06:43:33.676561+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  2019-07-13T06:43:33.676562+00:00 app[web.1]: django.setup(set_prefix=False)
  2019-07-13T06:43:33.676564+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
  2019-07-13T06:43:33.676565+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
  2019-07-13T06:43:33.676567+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
  2019-07-13T06:43:33.676568+00:00 app[web.1]: app_config = AppConfig.create(entry)
  2019-07-13T06:43:33.676569+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
  2019-07-13T06:43:33.676571+00:00 app[web.1]: mod = import_module(mod_path)
  2019-07-13T06:43:33.676572+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
  2019-07-13T06:43:33.676574+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
  2019-07-13T06:43:33.676576+00:00 app[web.1]: ModuleNotFoundError: No module named 'src'
  2019-07-13T06:43:33.676797+00:00 app[web.1]: [2019-07-13 06:43:33 +0000] [11] [INFO] Worker exiting (pid:
  11)
  2019-07-13T06:43:33.743217+00:00 app[web.1]: Traceback (most recent call last):
  2019-07-13T06:43:33.743229+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 210, in run
  2019-07-13T06:43:33.743551+00:00 app[web.1]: self.sleep()
  2019-07-13T06:43:33.743557+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 360, in sleep
  2019-07-13T06:43:33.743786+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
  2019-07-13T06:43:33.743792+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
  2019-07-13T06:43:33.743969+00:00 app[web.1]: self.reap_workers()
  2019-07-13T06:43:33.744000+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
  2019-07-13T06:43:33.744238+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
  2019-07-13T06:43:33.744322+00:00 app[web.1]: gunicorn.errors.HaltServer: &lt;HaltServer 'Worker failed to boot.' 3&gt;
  2019-07-13T06:43:33.744327+00:00 app[web.1]:
  2019-07-13T06:43:33.744330+00:00 app[web.1]: During handling of the above exception, another exception occurred:
  2019-07-13T06:43:33.744332+00:00 app[web.1]:
  2019-07-13T06:43:33.744336+00:00 app[web.1]: Traceback (most recent call last):
  2019-07-13T06:43:33.744346+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in &lt;module&gt;
  2019-07-13T06:43:33.744482+00:00 app[web.1]: sys.exit(run())
  2019-07-13T06:43:33.744486+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
  2019-07-13T06:43:33.744632+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  2019-07-13T06:43:33.744639+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 223, in run
  2019-07-13T06:43:33.744843+00:00 app[web.1]: super(Application, self).run()
  2019-07-13T06:43:33.744850+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 72, in run
  2019-07-13T06:43:33.744985+00:00 app[web.1]: Arbiter(self).run()
  2019-07-13T06:43:33.744991+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 232, in run
  2019-07-13T06:43:33.745162+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
  2019-07-13T06:43:33.745168+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 345, in halt
  2019-07-13T06:43:33.745377+00:00 app[web.1]: self.stop()
  2019-07-13T06:43:33.745411+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 393, in stop
  2019-07-13T06:43:33.745611+00:00 app[web.1]: time.sleep(0.1)
  2019-07-13T06:43:33.745617+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
  2019-07-13T06:43:33.745787+00:00 app[web.1]: self.reap_workers()
  2019-07-13T06:43:33.745793+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
  2019-07-13T06:43:33.746031+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
  2019-07-13T06:43:33.746074+00:00 app[web.1]: gunicorn.errors.HaltServer: &lt;HaltServer 'Worker failed to boot.' 3&gt;
  </code></pre>
  
  <p>settings.py (I omitted things that I thought were not relevant)</p>
  
  <pre><code>import django_heroku
  import dj_database_url
  import os
  
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'rest_framework',
      'src.apps.SrcConfig',
      'corsheaders',
  ]
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  ROOT_URLCONF = 'webadvisorapi.urls'
  
  WSGI_APPLICATION = 'webadvisorapi.wsgi.application'
  
  STATIC_URL = '/static/'
  
  django_heroku.settings(locals()) 
  </code></pre>
  
  <p>Procfile</p>
  
  <pre><code>web: gunicorn webadvisorapi.webadvisorapi.wsgi --log-file -
  </code></pre>
  
  <p>wsgi.py</p>
  
  <pre><code>import os
  
  from django.core.wsgi import get_wsgi_application
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webadvisorapi.webadvisorapi.settings')
  
  application = get_wsgi_application()
  </code></pre>
  
  <p>apps.py</p>
  
  <pre><code>from django.apps import AppConfig
  
  class SrcConfig(AppConfig):
      name = 'src'
  </code></pre>
  
  <p>webadvisorapi/urls.py</p>
  
  <pre><code>from django.contrib import admin
  from django.urls import path, include
  
  urlpatterns = [
      path('admin/', admin.site.urls),
      path('', include('src.urls')),
  ]
  </code></pre>
  
  <p>I'm really not sure what the problem is here, given that this path worked fine in my localhost. I would appreciate any kind of help.</p>