I
I
Ilya Erokhin2016-06-23 17:26:23
Python
Ilya Erokhin, 2016-06-23 17:26:23

Python3+uwsgi on Ubuntu 16.04. No module named 'encodings' - how to find out what's wrong?

Ubuntu 16.04, Python3, virtualenvwrapper, uwsgi. Python and uwsgi are standard system ones.
Error when starting the uwsgi service, key lines in the log -

Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

UPD!!!: Removed the line
home=/root/.virtualenvs/vek/bin/python
and everything worked. As a last resort, I will use Python's hologlobal environment, but what's the problem?

Wherever I didn’t dig, my thoughts ran out. What could be the problem and how to look for it at all (detail the logs, diagnose something else)?
All the key details, if something is missing - I will add.
# cat /etc/uwsgi/apps-enabled/vek.ini 
[uwsgi]
plugins=python3
chdir=/srv/vek/django
module=vek.wsgi:application
home=/root/.virtualenvs/vek/bin/python

# apt-get install uwsgi-plugin-python3 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
uwsgi-plugin-python3 is already the newest version (2.0.12-5ubuntu3).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

# cat /var/log/uwsgi/app/vek.log
...
Thu Jun 23 17:12:52 2016 - *** Starting uWSGI 2.0.12-debian (64bit) on [Thu Jun 23 17:12:51 2016] ***
Thu Jun 23 17:12:52 2016 - compiled with version: 5.3.1 20160412 on 13 April 2016 08:36:06
Thu Jun 23 17:12:52 2016 - os: Linux-4.4.0-24-generic #43-Ubuntu SMP Wed Jun 8 19:27:37 UTC 2016
Thu Jun 23 17:12:52 2016 - nodename: vek-dverey.ru
Thu Jun 23 17:12:52 2016 - machine: x86_64
Thu Jun 23 17:12:52 2016 - clock source: unix
Thu Jun 23 17:12:52 2016 - pcre jit disabled
Thu Jun 23 17:12:52 2016 - detected number of CPU cores: 1
Thu Jun 23 17:12:52 2016 - current working directory: /
Thu Jun 23 17:12:52 2016 - writing pidfile to /run/uwsgi/app/vek/pid
Thu Jun 23 17:12:52 2016 - detected binary path: /usr/bin/uwsgi-core
Thu Jun 23 17:12:52 2016 - setgid() to 33
Thu Jun 23 17:12:52 2016 - setuid() to 33
Thu Jun 23 17:12:52 2016 - chdir() to /srv/vek/django
Thu Jun 23 17:12:52 2016 - your processes number limit is 3912
Thu Jun 23 17:12:52 2016 - your memory page size is 4096 bytes
Thu Jun 23 17:12:52 2016 - detected max file descriptor number: 1024
Thu Jun 23 17:12:52 2016 - lock engine: pthread robust mutexes
Thu Jun 23 17:12:52 2016 - thunder lock: disabled (you can enable it with --thunder-lock)
Thu Jun 23 17:12:52 2016 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/vek/socket fd 3
Thu Jun 23 17:12:52 2016 - Python version: 3.5.1+ (default, Mar 30 2016, 22:46:26)  [GCC 5.3.1 20160330]
Thu Jun 23 17:12:52 2016 - Set PythonHome to /root/.virtualenvs/vek/bin/python
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f0abc3b7780 (most recent call first):

# /root/.virtualenvs/vek/bin/python 
Python 3.5.1+ (default, Mar 30 2016, 22:46:26) 
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import encodings
>>> encodings
<module 'encodings' from '/root/.virtualenvs/vek/lib/python3.5/encodings/__init__.py'>
>>>

I suspect that some wrong Python is being used, but in the uwsgi log the version is correct
UPD: I checked the version of the wrong plugin naming:
# uwsgi<TAB key>
uwsgi           uwsgi-core      uwsgi_python3   uwsgi_python35

It can be seen that there are plugins uwsgi_python3 and uwsgi_python35. I tried to change the name of the plugin in ini to python35 - the log is absolutely the same.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-06-23
@sim3x

Get a user
Get him a directory in / home
Put everything there
In uwsgi specify which user you need to run
To use plugins=python3you need to put uwsgi-plugin-python3

I
IRIP, 2018-02-02
@IRIP

where did you remove the line
home=/root/.virtualenvs/vek/bin/python

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question