title: ImportError: No module named 'environ' with gunicorn on django
body: <p>I'm using Ubuntu 14.04 with Django 2.0.5 with Django Cookiecutter. I am trying to start a Django server on DigitalOcean and trying to bind gunicorn to 0.0.0.0:8000. python manage.py runserver works fine, but the issue is that it says it can't import environ. Any tips are greatly appreciated, Thanks.</p>
  <p>I've ran</p>
  <blockquote>
  <p>pip install-r base.txt</p>
  <p>pip install-r local.txt</p>
  <p>pip install-r production.txt</p>
  </blockquote>
  <p>and reinstalled django-environ 0.4.4</p>
  <p><strong>This is the error that I receive when I run the following gunicorn command:</strong></p>
  <blockquote>
  <p>sudo gunicorn --bind 0.0.0.0:8000 config.wsgi:application</p>
  </blockquote>
  <pre><code>(venv) root@django-manaland:/home/django/mana/manaland# sudo gunicorn -b 0.0.0.0:8000 config.wsgi:application
  [2018-05-07 00:12:32 +0000] [20500] [INFO] Starting gunicorn 19.8.1
  [2018-05-07 00:12:32 +0000] [20500] [INFO] Listening at: http://0.0.0.0:8000 (20500)
  [2018-05-07 00:12:32 +0000] [20500] [INFO] Using worker: sync
  [2018-05-07 00:12:32 +0000] [20503] [INFO] Booting worker with pid: 20503
  [2018-05-07 00:12:32 +0000] [20503] [ERROR] Exception in worker process
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/arbiter.py&quot;, line 583, in spawn_worker
      worker.init_process()
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/workers/base.py&quot;, line 129, in init_process
      self.load_wsgi()
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/workers/base.py&quot;, line 138, in load_wsgi
      self.wsgi = self.app.wsgi()
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/app/base.py&quot;, line 67, in wsgi
      self.callable = self.load()
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/app/wsgiapp.py&quot;, line 52, in load
      return self.load_wsgiapp()
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/app/wsgiapp.py&quot;, line 41, in load_wsgiapp
      return util.import_app(self.app_uri)
    File &quot;/usr/local/lib/python3.5/dist-packages/gunicorn/util.py&quot;, line 350, in import_app
      __import__(module)
    File &quot;/home/django/mana/manaland/config/wsgi.py&quot;, line 38, in &lt;module&gt;
      application = get_wsgi_application()
    File &quot;/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py&quot;, line 13, in get_wsgi_application
      django.setup(set_prefix=False)
    File &quot;/usr/local/lib/python3.5/dist-packages/django/__init__.py&quot;, line 22, in setup
      configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    File &quot;/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py&quot;, line 56, in __getattr__
      self._setup(name)
    File &quot;/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py&quot;, line 41, in _setup
      self._wrapped = Settings(settings_module)
    File &quot;/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py&quot;, line 110, in __init__
      mod = importlib.import_module(self.SETTINGS_MODULE)
    File &quot;/usr/lib/python3.5/importlib/__init__.py&quot;, line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;/home/django/mana/manaland/config/settings/production.py&quot;, line 3, in &lt;module&gt;
      from .base import *  # noqa
    File &quot;/home/django/mana/manaland/config/settings/base.py&quot;, line 5, in &lt;module&gt;
      import environ
  ImportError: No module named 'environ'
  [2018-05-07 00:12:32 +0000] [20503] [INFO] Worker exiting (pid: 20503)
  [2018-05-07 00:12:32 +0000] [20500] [INFO] Shutting down: Master
  [2018-05-07 00:12:32 +0000] [20500] [INFO] Reason: Worker failed to boot.
  </code></pre>
  <p>base.py file</p>
  <pre><code>&quot;&quot;&quot;
  Base settings to build other settings files upon.
  &quot;&quot;&quot;
  
  import environ
  
  ROOT_DIR = environ.Path(__file__) - 3  # (manaland/config/settings/base.py - 3 = manaland/)
  APPS_DIR = ROOT_DIR.path('manaland')
  
  env = environ.Env()
  
  READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False)
  if READ_DOT_ENV_FILE:
      # OS environment variables take precedence over variables from .env
      env.read_env(str(ROOT_DIR.path('.env')))
  
  # GENERAL
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#debug
  DEBUG = env.bool('DJANGO_DEBUG', False)
  # Local time zone. Choices are
  # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  # though not all of them may be available with every OS.
  # In Windows, this must be set to your system time zone.
  TIME_ZONE = 'UTC'
  # https://docs.djangoproject.com/en/dev/ref/settings/#language-code
  LANGUAGE_CODE = 'en-us'
  # https://docs.djangoproject.com/en/dev/ref/settings/#site-id
  SITE_ID = 1
  # https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
  USE_I18N = True
  # https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
  USE_L10N = True
  # https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
  USE_TZ = True
  
  # DATABASES
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#databases
  
  DATABASES = {
      'default': env.db('DATABASE_URL', default='postgres:///manaland'),
  }
  DATABASES['default']['ATOMIC_REQUESTS'] = True
  
  # URLS
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
  ROOT_URLCONF = 'config.urls'
  # https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
  WSGI_APPLICATION = 'config.wsgi.application'
  
  # APPS
  # ------------------------------------------------------------------------------
  DJANGO_APPS = [
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.sites',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      # 'django.contrib.humanize', # Handy template tags
      'django.contrib.admin',
  ]
  THIRD_PARTY_APPS = [
      'crispy_forms',
      'allauth',
      'allauth.account',
      'allauth.socialaccount',
      'rest_framework',
  ]
  LOCAL_APPS = [
      'manaland.users.apps.UsersConfig',
      # Your stuff: custom apps go here
  ]
  # https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
  INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
  
  # MIGRATIONS
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules
  MIGRATION_MODULES = {
      'sites': 'manaland.contrib.sites.migrations'
  }
  
  # AUTHENTICATION
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
  AUTHENTICATION_BACKENDS = [
      'django.contrib.auth.backends.ModelBackend',
      'allauth.account.auth_backends.AuthenticationBackend',
  ]
  # https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
  AUTH_USER_MODEL = 'users.User'
  # https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
  LOGIN_REDIRECT_URL = 'users:redirect'
  # https://docs.djangoproject.com/en/dev/ref/settings/#login-url
  LOGIN_URL = 'account_login'
  
  # PASSWORDS
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers
  PASSWORD_HASHERS = [
      # https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
      'django.contrib.auth.hashers.Argon2PasswordHasher',
      'django.contrib.auth.hashers.PBKDF2PasswordHasher',
      'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
      'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
      'django.contrib.auth.hashers.BCryptPasswordHasher',
  ]
  # https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
  AUTH_PASSWORD_VALIDATORS = [
      {
          'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
  ]
  
  # MIDDLEWARE
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#middleware
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  # STATIC
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#static-root
  STATIC_ROOT = str(ROOT_DIR('staticfiles'))
  # https://docs.djangoproject.com/en/dev/ref/settings/#static-url
  STATIC_URL = '/static/'
  # https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
  STATICFILES_DIRS = [
      str(APPS_DIR.path('static')),
  ]
  # https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
  STATICFILES_FINDERS = [
      'django.contrib.staticfiles.finders.FileSystemFinder',
      'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  ]
  
  # MEDIA
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#media-root
  MEDIA_ROOT = str(APPS_DIR('media'))
  # https://docs.djangoproject.com/en/dev/ref/settings/#media-url
  MEDIA_URL = '/media/'
  
  # TEMPLATES
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#templates
  TEMPLATES = [
      {
          # https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          # https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
          'DIRS': [
              str(APPS_DIR.path('templates')),
          ],
          'OPTIONS': {
              # https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
              'debug': DEBUG,
              # https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
              # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
              'loaders': [
                  'django.template.loaders.filesystem.Loader',
                  'django.template.loaders.app_directories.Loader',
              ],
              # https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.template.context_processors.i18n',
                  'django.template.context_processors.media',
                  'django.template.context_processors.static',
                  'django.template.context_processors.tz',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  # http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
  CRISPY_TEMPLATE_PACK = 'bootstrap4'
  
  # FIXTURES
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#fixture-dirs
  FIXTURE_DIRS = (
      str(APPS_DIR.path('fixtures')),
  )
  
  # EMAIL
  # ------------------------------------------------------------------------------
  # https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
  EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
  
  # ADMIN
  # ------------------------------------------------------------------------------
  # Django Admin URL regex.
  ADMIN_URL = r'^admin/'
  # https://docs.djangoproject.com/en/dev/ref/settings/#admins
  ADMINS = [
      (&quot;&quot;&quot;dom&quot;&quot;&quot;, 'hello@manaland.io'),
  ]
  # https://docs.djangoproject.com/en/dev/ref/settings/#managers
  MANAGERS = ADMINS
  
  
  # django-allauth
  # ------------------------------------------------------------------------------
  ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', True)
  # https://django-allauth.readthedocs.io/en/latest/configuration.html
  ACCOUNT_AUTHENTICATION_METHOD = 'username'
  # https://django-allauth.readthedocs.io/en/latest/configuration.html
  ACCOUNT_EMAIL_REQUIRED = True
  # https://django-allauth.readthedocs.io/en/latest/configuration.html
  ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
  # https://django-allauth.readthedocs.io/en/latest/configuration.html
  ACCOUNT_ADAPTER = 'manaland.users.adapters.AccountAdapter'
  # https://django-allauth.readthedocs.io/en/latest/configuration.html
  SOCIALACCOUNT_ADAPTER = 'manaland.users.adapters.SocialAccountAdapter'
  
  
  # Your stuff...
  # ------------------------------------------------------------------------------
  </code></pre>
  <p>production.py imports</p>
  <pre><code>import logging
  
  from .base import *  # noqa
  from .base import env
  </code></pre>
  <p>manage.py</p>
  <pre><code>#!/usr/bin/env python
  import os
  import sys
  
  if __name__ == &quot;__main__&quot;:
      os.environ.setdefault(&quot;DJANGO_SETTINGS_MODULE&quot;, &quot;config.settings.production&quot;)
  
      try:
          from django.core.management import execute_from_command_line
      except ImportError:
          # The above import may fail for some other reason. Ensure that the
          # issue is really that Django is missing to avoid masking other
          # exceptions on Python 2.
          try:
              import django  # noqa
          except ImportError:
              raise ImportError(
                  &quot;Couldn't import Django. Are you sure it's installed and &quot;
                  &quot;available on your PYTHONPATH environment variable? Did you &quot;
                  &quot;forget to activate a virtual environment?&quot;
              )
  
          raise
  
      # This allows easy placement of apps within the interior
      # manaland directory.
      current_path = os.path.dirname(os.path.abspath(__file__))
      sys.path.append(os.path.join(current_path, &quot;manaland&quot;))
  
      execute_from_command_line(sys.argv)
  </code></pre>