我正在尝试通过运行Raspbian GNU / Linux 9(延伸)的Raspberry Pi上的uWSGI运行Django应用程序,它来自发行版的Python 3.5,我编译并安装了Python 3.6作为替代方案。这些是我目前的Python安装:
我还为位于python3.6
的应用创建了基于~/.virtualenvs
的virtualenv。问题是该服务抱怨无法获取语言环境编码:
致命Python错误:Py_Initialize:无法获取语言环境编码
由于缺少模块:
ImportError:没有名为'encodings'的模块
但是,如果我开始我的virtualenv并发出:
import encodings
完全正常:
>>> import encodings
>>> encodings
<module 'encodings' from '/home/ariel/.virtualenvs/you2ogg/lib/python3.6/encodings/__init__.py'>
这是我的service.ini
文件的样子:
[uwsgi]
plugins = python3
chdir = /srv/user/app/
module = app.wsgi
home = /home/user/.virtualenvs/app/
master = true
processes = 10
socket = /srv/user/app/app.sock
chmod-socket = 666
vacuum = true
uid = 1000
gid = 1000
这就是日志对我服务的评价:
Wed Dec 20 11:29:51 2017 - *** Starting uWSGI 2.0.14-debian (32bit) on [Wed Dec 20 11:29:49 2017] ***
Wed Dec 20 11:29:51 2017 - compiled with version: 6.2.1 20161124 on 18 December 2016 15:05:38
Wed Dec 20 11:29:51 2017 - os: Linux-4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017
Wed Dec 20 11:29:51 2017 - nodename: rpi3
Wed Dec 20 11:29:51 2017 - machine: armv7l
Wed Dec 20 11:29:51 2017 - clock source: unix
Wed Dec 20 11:29:51 2017 - pcre jit disabled
Wed Dec 20 11:29:51 2017 - detected number of CPU cores: 4
Wed Dec 20 11:29:51 2017 - current working directory: /
Wed Dec 20 11:29:51 2017 - writing pidfile to /run/uwsgi/app/you2ogg/pid
Wed Dec 20 11:29:51 2017 - detected binary path: /usr/bin/uwsgi-core
Wed Dec 20 11:29:51 2017 - setgid() to 1000
Wed Dec 20 11:29:51 2017 - setuid() to 1000
Wed Dec 20 11:29:51 2017 - chdir() to /srv/ariel/you2ogg/
Wed Dec 20 11:29:51 2017 - your processes number limit is 7346
Wed Dec 20 11:29:51 2017 - your memory page size is 4096 bytes
Wed Dec 20 11:29:51 2017 - detected max file descriptor number: 1024
Wed Dec 20 11:29:51 2017 - lock engine: pthread robust mutexes
Wed Dec 20 11:29:51 2017 - thunder lock: disabled (you can enable it with --thunder-lock)
Wed Dec 20 11:29:51 2017 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/you2ogg/socket fd 3
Wed Dec 20 11:29:51 2017 - uwsgi socket 1 bound to UNIX address /srv/ariel/you2ogg/you2ogg.sock fd 5
Wed Dec 20 11:29:51 2017 - Python version: 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124]
Wed Dec 20 11:29:51 2017 - Set PythonHome to /home/ariel/.virtualenvs/you2ogg/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x76f35000 (most recent call first):
请注意,显然uWSGI坚持使用Python 3.5来了解谁知道什么,并根据其他一些问题设置PYTHONPATH解决了这个问题,但是我必须注意这个应用程序在Fedora机器上运行完全正常那个var也没有设置。
这里有什么问题?
答案 0 :(得分:2)
我终于找到了问题所在。事实证明,uWSGI的python插件以某种方式绑定到python版本,例如:
所以我必须按照this guide编译并手动安装我的Python 3.6插件:
PYTHON=python3.6 uwsgi --build-plugin "/usr/src/uwsgi/plugins/python python36"
mv python36_plugin.so /usr/lib/uwsgi/plugins/python36_plugin.so
chmod 644 /usr/lib/uwsgi/plugins/python36_plugin.so
它现在将Python 3.6.X显示为uWSGI服务init日志上的Python版本,并且应用程序正常工作。它在Fedora中工作的原因可能是因为Fedora 26它带有Python 3.6作为默认的python3版本,所以这个插件可能是开箱即用的。