title: 502 Bad Gateway in GAE with Django, & Log say "libBLT.2.5.so.8.6 No such file or directory"
body: <ul>
  <li>Django 4.0.4</li>
  <li>Python 3.8.9</li>
  </ul>
  <p>I deployed Django App to GAE.
  But I got &quot;502 Bad Gateway&quot; error. And I checked server logs. That is below.</p>
  <pre><code>Traceback (most recent call last):
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/arbiter.py&quot;, line 589, in spawn_worker
     worker.init_process()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/workers/base.py&quot;, line 134, in init_process
     self.load_wsgi()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/workers/base.py&quot;, line 146, in load_wsgi
     self.wsgi = self.app.wsgi()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/app/base.py&quot;, line 67, in wsgi
     self.callable = self.load()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py&quot;, line 58, in load
     return self.load_wsgiapp()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py&quot;, line 48, in load_wsgiapp
     return util.import_app(self.app_uri)
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/gunicorn/util.py&quot;, line 359, in import_app
     mod = importlib.import_module(module)
   File &quot;/opt/python3.8/lib/python3.8/importlib/__init__.py&quot;, line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1014, in _gcd_import
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 991, in _find_and_load
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 843, in exec_module
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
   File &quot;/workspace/SakeMarksV1/wsgi.py&quot;, line 16, in &lt;module&gt;
     application = get_wsgi_application()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/django/core/wsgi.py&quot;, line 12, in get_wsgi_application
     django.setup(set_prefix=False)
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/django/__init__.py&quot;, line 24, in setup
     apps.populate(settings.INSTALLED_APPS)
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/django/apps/registry.py&quot;, line 116, in populate
     app_config.import_models()
   File &quot;/layers/google.python.pip/pip/lib/python3.8/site-packages/django/apps/config.py&quot;, line 304, in import_models
     self.models_module = import_module(models_module_name)
   File &quot;/opt/python3.8/lib/python3.8/importlib/__init__.py&quot;, line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1014, in _gcd_import
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 991, in _find_and_load
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 843, in exec_module
   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
   File &quot;/workspace/website/models.py&quot;, line 1, in &lt;module&gt;
     import turtledemo.nim
   File &quot;/opt/python3.8/lib/python3.8/turtledemo/nim.py&quot;, line 13, in &lt;module&gt;
     import turtle
   File &quot;/opt/python3.8/lib/python3.8/turtle.py&quot;, line 107, in &lt;module&gt;
     import tkinter as TK
   File &quot;/opt/python3.8/lib/python3.8/tkinter/__init__.py&quot;, line 36, in &lt;module&gt;
     import _tkinter # If this fails your Python may not be configured for Tk
  ImportError: libBLT.2.5.so.8.6: cannot open shared object file: No such file or directory 
  </code></pre>
  <p>I'm thinking that GAE instance has no TK or gunicorn is not working.
  Do anyone know about this kind of problem?
  Thank you.</p>
  <p>-- app.yaml --</p>
  <pre><code>runtime: python38
  
  instance_class: F1
  
  env: standard
  
  entrypoint: gunicorn -b :$PORT &lt;PROJECT_NAME&gt;.wsgi:application
  
  includes:
      - secret.yaml
  
  handlers:
      - url: /static
        static_dir: static/
      - url: /.*
        script: auto
        secure: always
  
  automatic_scaling:
    max_instances: 2
  </code></pre>
  <p>-- settings/base.py --</p>
  <pre><code>from pathlib import Path
  import os
  from dotenv import load_dotenv
  
  load_dotenv()
  
  BASE_DIR = Path(__file__).resolve().parent.parent.parent
  
  AUTH_USER_MODEL = 'website.User'
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'website',
      'widget_tweaks',
      'social_django',
      'corsheaders',
      'django_cleanup',
      'stdimage',
      'storages',
  ]
  
  MIDDLEWARE = [
      'django.middleware.gzip.GZipMiddleware',
      'corsheaders.middleware.CorsMiddleware',
      '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',
      'social_django.middleware.SocialAuthExceptionMiddleware',
  ]
  
  CORS_ORIGIN_ALLOW_ALL = True
  
  ROOT_URLCONF = '&lt;PROJECT_NAME&gt;.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [BASE_DIR / 'templates']
          ,
          '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',
                  'social_django.context_processors.backends',
                  'social_django.context_processors.login_redirect',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = '&lt;PROJECT_NAME&gt;.wsgi.application'
  
  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',
      },
  ]
  
  AUTHENTICATION_BACKENDS = (
      'social_core.backends.open_id.OpenIdAuth',
      'social_core.backends.google.GoogleOAuth2',
      'social_core.backends.facebook.FacebookOAuth2',
      'django.contrib.auth.backends.ModelBackend',
  )
  
  EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  
  LANGUAGE_CODE = 'ja'
  
  TIME_ZONE = 'Asia/Tokyo'
  
  USE_I18N = True
  
  USE_TZ = True
  
  PROJECT_NAME = os.path.basename(BASE_DIR)
  
  STATIC_URL = 'static/'
  STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
  STATIC_ROOT = f'var/www/{PROJECT_NAME}/static'
  
  
  MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
  MEDIA_URL = '/media/'
  
  LOGIN_REDIRECT_URL = 'index'
  LOGOUT_REDIRECT_URL = 'index'
  
  DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  
  </code></pre>
  <p>-- settings/production.py --</p>
  <pre><code>from .base import *
  
  SECRET_KEY = os.getenv('SECRET_KEY')
  
  DEBUG = False
  
  ALLOWED_HOSTS = ['&lt;CUSTOM_DOMAIN&gt;']
  
  # データベース
  import pymysql
  
  pymysql.install_as_MySQLdb()
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'HOST': '/cloudsql/' + os.getenv('DB_CONNECTION_NAME'),
          'USER': os.getenv('DB_USER'),
          'PASSWORD': os.getenv('DB_PASSWORD'),
          'NAME': os.getenv('DB_NAME'),
      }
  }
  
  
  # ストレージ
  from google.oauth2 import service_account
  GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
      os.path.join(BASE_DIR, '&lt;PROJECT_NAME&gt;/settings/&lt;CREDENTIAL_FILE&gt;.json')
  )
  
  DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
  STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
  
  GS_BUCKET_NAME = os.getenv('GS_BUCKET_NAME')
  GS_PROJECT_ID = '&lt;PROJECT_NAME&gt;'
  
  # ソーシャルログイン
  SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.getenv('SOCIAL_AUTH_GOOGLE_OAUTH2_KEY')
  SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.getenv('SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET')
  
  SOCIAL_AUTH_FACEBOOK_KEY = os.getenv('SOCIAL_AUTH_FACEBOOK_KEY')
  SOCIAL_AUTH_FACEBOOK_SECRET = os.getenv('SOCIAL_AUTH_FACEBOOK_SECRET')
  </code></pre>