0

I am trying to do a uwsgi installation and I get the following error

Fatal Python error: initfsencoding: Unable to get the locale encoding

in my logs.

in my .ini I set the pythonpath

$ cat /etc/uwsgi/sites/exchange.ini

[uwsgi]
project = exchange
uid = kermit
base = /home/%(uid)

chdir = %(base)/www/src/%(project)
home = %(base)/Env/
module = %(project).wsgi:application
pythonpath = /home/kermit/www/src/exchange

master = true
processes = 5

socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true

but I can't tell if it is actually loaded

echo $PYTHONPATH

comes up empty, even when attempting from user environment

in my .bashrc I have

fi
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=~/Env
#export PYTHONPATH=~/www/src/exchange
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

directory structure:

(secret) kermit@tuna:~ $ ls
Env  exchange  pgp  uwsgi-ini  www
(secret) kermit@tuna:~ $ ls Env/
get_env_details  postactivate    postmkproject     postrmvirtualenv  predeactivate  premkvirtualenv  secret
initialize       postdeactivate  postmkvirtualenv  preactivate       premkproject   prermvirtualenv
(secret) kermit@tuna:~ $ ls www/
src  treefrog
(secret) kermit@tuna:~ $ ls www/src
exchange

$ cat www/src/exchange/exchange/settings.py

"""
Django settings for exchange project.

Generated by 'django-admin startproject' using Django 2.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'yeah_sure'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['10.9.8.30','192.168.43.252','127.0.0.1', 'localhost']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    #mystuff
    'userdash',
#    'userdash.apps.UserdashConfig',
]

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',
]

ROOT_URLCONF = 'exchange.urls'

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',
            ],
        },
    },
]

WSGI_APPLICATION = 'exchange.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

I did check other url on the topic, they all indicate my pythonpath is incorrect, I just can't figure how I am doing it incorrect.

How do you set the pythonpath correctly for uwsgi? I'm pretty sure that's where my error is.

UPDATE: full startup logs

Mar 23 10:10:31 tuna uwsgi[28169]: *** has_emperor mode detected (fd: 7) ***
Mar 23 10:10:31 tuna uwsgi[28169]: [uWSGI] getting INI configuration from exchange.ini
Mar 23 10:10:31 tuna uwsgi[28169]: *** Starting uWSGI 2.0.18 (32bit) on [Mon Mar 23 10:10:31 2020] ***
Mar 23 10:10:31 tuna uwsgi[28169]: compiled with version: 8.3.0 on 16 July 2019 12:06:45
Mar 23 10:10:31 tuna uwsgi[28169]: os: Linux-4.19.97+ #1294 Thu Jan 30 13:10:54 GMT 2020
Mar 23 10:10:31 tuna uwsgi[28169]: nodename: tuna.tradercoinz.com
Mar 23 10:10:31 tuna uwsgi[28169]: machine: armv6l
Mar 23 10:10:31 tuna uwsgi[28169]: clock source: unix
Mar 23 10:10:31 tuna uwsgi[28169]: pcre jit disabled
Mar 23 10:10:31 tuna uwsgi[28169]: detected number of CPU cores: 1
Mar 23 10:10:31 tuna uwsgi[28169]: current working directory: /etc/uwsgi/sites
Mar 23 10:10:31 tuna uwsgi[28169]: detected binary path: /usr/local/bin/uwsgi
Mar 23 10:10:31 tuna uwsgi[28169]: chdir() to /home/kermit/www/src/exchange
Mar 23 10:10:31 tuna uwsgi[28169]: your processes number limit is 3391
Mar 23 10:10:31 tuna uwsgi[28169]: your memory page size is 4096 bytes
Mar 23 10:10:31 tuna uwsgi[28169]: detected max file descriptor number: 1024
Mar 23 10:10:31 tuna uwsgi[28169]: lock engine: pthread robust mutexes
Mar 23 10:10:31 tuna uwsgi[28169]: thunder lock: disabled (you can enable it with --thunder-lock)
Mar 23 10:10:31 tuna uwsgi[28169]: uwsgi socket 0 bound to UNIX address /run/uwsgi/exchange.sock fd 3
Mar 23 10:10:31 tuna uwsgi[28169]: setuid() to 1001
Mar 23 10:10:31 tuna uwsgi[28169]: Python version: 3.7.3 (default, Dec 20 2019, 18:57:59)  [GCC 8.3.0]
Mar 23 10:10:31 tuna uwsgi[28169]: Set PythonHome to /home/kermit/Env/
Mar 23 10:10:31 tuna uwsgi[28169]: Fatal Python error: initfsencoding: Unable to get the locale encoding
Mar 23 10:10:31 tuna uwsgi[28169]: ModuleNotFoundError: No module named 'encodings'
Mar 23 10:10:31 tuna uwsgi[28169]: Current thread 0xb6f53010 (most recent call first):
Mar 23 10:10:31 tuna uwsgi[28169]: Mon Mar 23 10:10:31 2020 - [emperor] curse the uwsgi instance exchange.ini (pid: 32624)
Mar 23 10:10:34 tuna uwsgi[28169]: Mon Mar 23 10:10:34 2020 - [emperor] removed uwsgi instance exchange.ini
Mar 23 10:12:38 tuna uwsgi[28169]: *** has_emperor mode detected (fd: 7) ***
Mar 23 10:12:38 tuna uwsgi[28169]: [uWSGI] getting INI configuration from exchange.ini
Mar 23 10:12:38 tuna uwsgi[28169]: *** Starting uWSGI 2.0.18 (32bit) on [Mon Mar 23 10:12:38 2020] ***
Mar 23 10:12:38 tuna uwsgi[28169]: compiled with version: 8.3.0 on 16 July 2019 12:06:45
Mar 23 10:12:38 tuna uwsgi[28169]: os: Linux-4.19.97+ #1294 Thu Jan 30 13:10:54 GMT 2020
Mar 23 10:12:38 tuna uwsgi[28169]: nodename: tuna.tradercoinz.com
Mar 23 10:12:38 tuna uwsgi[28169]: machine: armv6l
Mar 23 10:12:38 tuna uwsgi[28169]: clock source: unix
Mar 23 10:12:38 tuna uwsgi[28169]: pcre jit disabled
Mar 23 10:12:38 tuna uwsgi[28169]: detected number of CPU cores: 1
Mar 23 10:12:38 tuna uwsgi[28169]: current working directory: /etc/uwsgi/sites
Mar 23 10:12:38 tuna uwsgi[28169]: detected binary path: /usr/local/bin/uwsgi
Mar 23 10:12:38 tuna uwsgi[28169]: chdir() to /home/kermit/www/src/exchange
Mar 23 10:12:38 tuna uwsgi[28169]: your processes number limit is 3391
Mar 23 10:12:38 tuna uwsgi[28169]: your memory page size is 4096 bytes
Mar 23 10:12:38 tuna uwsgi[28169]: detected max file descriptor number: 1024
Mar 23 10:12:38 tuna uwsgi[28169]: lock engine: pthread robust mutexes
Mar 23 10:12:38 tuna uwsgi[28169]: thunder lock: disabled (you can enable it with --thunder-lock)
Mar 23 10:12:38 tuna uwsgi[28169]: uwsgi socket 0 bound to UNIX address /run/uwsgi/exchange.sock fd 3
Mar 23 10:12:38 tuna uwsgi[28169]: setuid() to 1001
Mar 23 10:12:38 tuna uwsgi[28169]: Python version: 3.7.3 (default, Dec 20 2019, 18:57:59)  [GCC 8.3.0]
Mar 23 10:12:38 tuna uwsgi[28169]: Set PythonHome to /home/kermit/Env/
Mar 23 10:12:38 tuna uwsgi[28169]: Fatal Python error: initfsencoding: Unable to get the locale encoding
Mar 23 10:12:38 tuna uwsgi[28169]: ModuleNotFoundError: No module named 'encodings'
Mar 23 10:12:38 tuna uwsgi[28169]: Current thread 0xb6f8b010 (most recent call first):
Mar 23 10:12:38 tuna uwsgi[28169]: Mon Mar 23 10:12:38 2020 - [emperor] curse the uwsgi instance exchange.ini (pid: 32649)
Mar 23 10:12:41 tuna uwsgi[28169]: Mon Mar 23 10:12:41 2020 - [emperor] removed uwsgi instance exchange.ini
Mar 23 10:14:44 tuna uwsgi[28169]: *** has_emperor mode detected (fd: 7) ***
Mar 23 10:14:44 tuna uwsgi[28169]: [uWSGI] getting INI configuration from exchange.ini
Mar 23 10:14:44 tuna uwsgi[28169]: *** Starting uWSGI 2.0.18 (32bit) on [Mon Mar 23 10:14:44 2020] ***
Mar 23 10:14:44 tuna uwsgi[28169]: compiled with version: 8.3.0 on 16 July 2019 12:06:45
Mar 23 10:14:44 tuna uwsgi[28169]: os: Linux-4.19.97+ #1294 Thu Jan 30 13:10:54 GMT 2020
Mar 23 10:14:44 tuna uwsgi[28169]: nodename: tuna.tradercoinz.com
Mar 23 10:14:44 tuna uwsgi[28169]: machine: armv6l
Mar 23 10:14:44 tuna uwsgi[28169]: clock source: unix
Mar 23 10:14:44 tuna uwsgi[28169]: pcre jit disabled
Mar 23 10:14:44 tuna uwsgi[28169]: detected number of CPU cores: 1
Mar 23 10:14:44 tuna uwsgi[28169]: current working directory: /etc/uwsgi/sites
Mar 23 10:14:44 tuna uwsgi[28169]: detected binary path: /usr/local/bin/uwsgi
Mar 23 10:14:44 tuna uwsgi[28169]: chdir() to /home/kermit/www/src/exchange
Mar 23 10:14:44 tuna uwsgi[28169]: your processes number limit is 3391
Mar 23 10:14:44 tuna uwsgi[28169]: your memory page size is 4096 bytes
Mar 23 10:14:44 tuna uwsgi[28169]: detected max file descriptor number: 1024
Mar 23 10:14:44 tuna uwsgi[28169]: lock engine: pthread robust mutexes
Mar 23 10:14:44 tuna uwsgi[28169]: thunder lock: disabled (you can enable it with --thunder-lock)
Mar 23 10:14:44 tuna uwsgi[28169]: uwsgi socket 0 bound to UNIX address /run/uwsgi/exchange.sock fd 3
Mar 23 10:14:44 tuna uwsgi[28169]: setuid() to 1001
Mar 23 10:14:44 tuna uwsgi[28169]: Python version: 3.7.3 (default, Dec 20 2019, 18:57:59)  [GCC 8.3.0]
Mar 23 10:14:44 tuna uwsgi[28169]: Set PythonHome to /home/kermit/Env/
Mar 23 10:14:44 tuna uwsgi[28169]: Fatal Python error: initfsencoding: Unable to get the locale encoding
Mar 23 10:14:44 tuna uwsgi[28169]: ModuleNotFoundError: No module named 'encodings'
Mar 23 10:14:44 tuna uwsgi[28169]: Current thread 0xb6fa1010 (most recent call first):
Mar 23 10:14:44 tuna uwsgi[28169]: Mon Mar 23 10:14:44 2020 - [emperor] curse the uwsgi instance exchange.ini (pid: 32675)
Mar 23 10:14:47 tuna uwsgi[28169]: Mon Mar 23 10:14:47 2020 - [emperor] removed uwsgi instance exchange.ini
16
  • Your bashrc won't affect uwsgi. If you're using virtualenvs, have you looked at the virtualenv = uwsgi setting? Commented Mar 23, 2020 at 8:20
  • @AKX the guide I am using never calls for that setting digitalocean.com/community/tutorials/… Commented Mar 23, 2020 at 8:30
  • I don't know what to tell you - the Django deployments I've done with uwsgi do require that setting to properly use virtualenvs. Commented Mar 23, 2020 at 9:15
  • Secondly, don't use pythonpath, use chdir. Commented Mar 23, 2020 at 9:16
  • 1
    @AKX That was it. Thank you! I did try that before but I must have had another error going on at the time. Just never retried. Commented Mar 23, 2020 at 20:31

1 Answer 1

1

To expand on the comments:

Given the structure shown by

root@tuna:/home/kermit# ls /home/kermit/Env/
get_env_details  postactivate    postmkproject     postrmvirtualenv  predeactivate  premkvirtualenv  secret
initialize       postdeactivate  postmkvirtualenv  preactivate       premkproject   prermvirtualenv
root@tuna:/home/kermit# ls /home/kermit/Env/secret/
bin  include  lib
root@tuna:/home/kermit# ls /home/kermit/Env/secret/bin/
activate       activate.ps1      django-admin     easy_install-3.7  pip3          postdeactivate  __pycache__  python3.7      uwsgi
activate.csh   activate_this.py  django-admin.py  get_env_details   pip3.7        preactivate     python       python-config  wheel
activate.fish  activate.xsh      easy_install     pip               postactivate  predeactivate   python3      sqlformat

the correct value for virtualenv = should be /home/kermit/Env/secret.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.