【问题标题】:How to configure uwsgi to work with a specific version of python?如何配置 uwsgi 以使用特定版本的 python?
【发布时间】:2023-04-04 20:38:01
【问题描述】:

我使用 Debian 9 uwsgi 和 nginx 作为几个 Django 站点的服务器。默认情况下,Debian 有 python 3.5。 uwsgi 全局安装

sudo -H pip3 install uwsgi

我决定将网站转移到 python 3.7。为此,我将源文件中的新版本 python 3.7 安装到 /usr/local/bin/python3.7 文件夹中。

我还重新创建了一个虚拟环境(与之前的名称相同)

mkvirtualenv -p /usr/local/bin/python3.7 protrack

但现在我有一个错误,uwsgi 仍然使用 python 3.5。

● uwsgi.service - uWSGI Emperor service
   Loaded: loaded (/etc/systemd/system/uwsgi.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-12-13 15:06:55 UTC; 3 days ago
  Process: 2102 ExecStartPre=/bin/bash -c mkdir -p /run/uwsgi; chown gk:www-data /run/uwsgi (code=exited, status=0/SUCCESS)
 Main PID: 2106 (uwsgi)
   Status: "The Emperor is governing 1 vassals"
    Tasks: 7 (limit: 4915)
   CGroup: /system.slice/uwsgi.service
           ├─2106 /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
           ├─2110 /usr/local/bin/uwsgi --ini myblog.ini
           ├─2112 /usr/local/bin/uwsgi --ini myblog.ini
           ├─2113 /usr/local/bin/uwsgi --ini myblog.ini
           ├─2114 /usr/local/bin/uwsgi --ini myblog.ini
           ├─2115 /usr/local/bin/uwsgi --ini myblog.ini
           └─2116 /usr/local/bin/uwsgi --ini myblog.ini

Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: thunder lock: disabled (you can enable it with --thunder-lock)
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: uwsgi socket 0 bound to UNIX address /run/uwsgi/protrack.sock fd 3
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: setuid() to 1001
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: Python version: 3.5.3 (default, Sep 27 2018, 17:25:39)  [GCC 6.3.0 20170516]
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: Set PythonHome to /home/gk/Env/protrack
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: Fatal Python error: Py_Initialize: Unable to get the locale encoding
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: ImportError: No module named 'encodings'
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: Current thread 0x00007fd43cf73b40 (most recent call first):
Снж 16 16:21:59 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: Mon Dec 16 16:21:59 2019 - [emperor] curse the uwsgi instance protrack.ini (pid: 22782)
Снж 16 16:22:02 server-1537436012497-s-1vcpu-1gb-fra1-01 uwsgi[2106]: Mon Dec 16 16:22:02 2019 - [emperor] removed uwsgi instance protrack.ini

如何重新配置​​ uwsgi 以使用 python 3.7?

/etc/uwsgi/sites/protrack.ini

[uwsgi]
project = protrack
uid = gk
base = /home/%(uid)

chdir = %(base)/%(project)
home = %(base)/Env/protrack
module = protrack.wsgi:application

master = true
processes = 5

# Finish off the configuration with the following lines
socket = /run/uwsgi/protrack.sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true

【问题讨论】:

    标签:
    python
    django
    debian
    uwsgi