uwsgi升级到python3.7以修复ImportError:没有名为'encodings'的模块

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

老实说,我不知道自己在做什么,所以请对我保持温柔。我正在尝试使用uwsgi在aws ubuntu实例上运行django应用程序。我有一个运行python3.7的虚拟环境,但是当我尝试运行uwsgi时。我在日志中得到这个:

*** Starting uWSGI 2.0.14 (64bit) on [Sun Jan  5 14:51:32 2020] ***
compiled with version: 5.4.0 20160609 on 20 October 2016 05:56:34
os: Linux-4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018
nodename: ip-172-31-41-139
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /home/ubuntu/web/graff
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3804
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /home/ubuntu/web/graffuwsgi.sock fd 3
Python version: 3.5.2 (default, Oct  8 2019, 13:06:37)  [GCC 5.4.0 20160609]
Set PythonHome to /home/ubuntu/.virtualenvs/graff
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

这是我的uwsgi.conf

# file: /etc/init/graffuwsgi.conf
description "uWSGI server for graff"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
exec /usr/local/bin/uwsgi --home /home/ubuntu/web/graff/ --socket /home/ubuntu/web/graffuwsgi.sock --chmod-socket=666 --module=graff.wsgi --pythonpath /home/ubuntu/web -H /home/ubuntu/.virtualenvs/graff --logto /home/ubuntu/web/logs/graffuwsgi.log --chdir=/home/ubuntu/web/graff --chmod-socket=666

似乎python3.5不再起作用。我觉得最近我不得不在多个地方用3.7替换python3.5来修复各种错误,而且我的想法是,如果我可以让uwsgi运行python3.7而不是3.5,那么它将解决此错误。太。无论如何,非常感谢您的帮助。

uwsgi django-wsgi
1个回答
0
投票

看起来您的uwsgi是使用不同的python版本编译的,请确保您使用python 3.5进行编译

PYTHON=python3.5 uwsgi --build-plugin "/usr/src/uwsgi/plugins/python python35"
mv python35_plugin.so /usr/lib/uwsgi/plugins/python35_plugin.so
chmod 644 /usr/lib/uwsgi/plugins/python35_plugin.so

您可以遵循本指南:

https://www.paulox.net/2017/04/04/how-to-use-uwsgi-with-python3-6-in-ubuntu/

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