django w / uwsgi致命的Python错误:initfsencoding:无法获取区域设置编码

问题描述 投票:0回答:1

我正在尝试安装uwsgi,但出现以下错误

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

在我的日志中。

在我的.ini中,我设置了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

但是我不知道它是否真的被加载

echo $PYTHONPATH

即使在用户环境中尝试时也为空

在我的.bashrc中,我有

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

目录结构:

(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/')

我确实检查了该主题上的其他URL,它们都表明我的pythonpath不正确,只是无法弄清楚我的操作方式是否不正确。

您如何为uwsgi正确设置pythonpath?我很确定这就是我的错误所在。

更新:完整的启动日志

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
python django uwsgi django-wsgi
1个回答
0
投票

展开评论:

给出]所示的结构>

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

virtualenv =的正确值应为/home/kermit/Env/secret

© www.soinside.com 2019 - 2024. All rights reserved.