uwsgi升级到python3.7以修复导入错误:没有名为'的模块;编码';

uwsgi升级到python3.7以修复导入错误:没有名为'的模块;编码';,uwsgi,django-wsgi,Uwsgi,Django Wsgi,老实说,我不知道我在做什么,所以对我温柔一点。我正在尝试使用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: Lin

老实说,我不知道我在做什么,所以对我温柔一点。我正在尝试使用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是用不同的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
您可以按照以下指南操作:


错误源是PythonHome(pyhome、venv、home)设置

您的路径
/home/ubuntu/.virtualenvs/graff
是否适合Python要求

简言之: 使用(pp)并让系统查找模块

您可以在uwsgi配置中将多个重复选项设置为自定义模块搜索,例如:

pythonpath = /opt/web2py/
pythonpath = /opt/anaconda/lib/python3.9/site-packages/
所以,我也犯了同样的错误。它是通过编辑uwsgi附庸配置修复的


我认为问题的核心是虚拟环境是用符号链接创建的,或者有一些内部相对路径,因此uwsgi内部的一个孤立进程找不到模块。

错误:找不到目录'/usr/src/uwsgi/plugins/python'
关于路径应该是什么的其他猜测?奇怪的是,我已经在这台服务器上的六个其他django应用程序上使用了uwsgi,没有任何问题。唯一的区别是,这是一个python3.7环境和django的更新版本。