Ubuntu

uWSGI 無法載入 virtualenv

  • January 21, 2021

我正在使用 nginx 和 uWSGI 設置 Python 應用程序。我的依賴項位於 virtualenv 中。如果我手動啟動 virtualenv,一切都可以通過執行以下命令進行:

uwsgi --ini uwsgi.ini

但是如果我嘗試在 virtualenv 停用的情況下執行相同的命令,我會在輸出中得到這個(雖然沒有特定的權限錯誤):

*** no app loaded. going in full dynamic mode ***

同理,Emperor載入ini文件時,也無法執行app。我的理解是使用該home選項應該啟動 virtualenv,但它似乎沒有工作。(wsgi.py載入的模組也會啟動 virtualenv,所以我什至不確定為什麼我應該在那之前這樣做……)

這是我的uwsgi.ini

[uwsgi]
uid = 1000
socket = 127.0.0.1:8000
workers = 3
master = true
processes = 5
module = wsgi:application
chdir = /home/laststatement/app/laststatement
home = /home/laststatement/.virtualenvs/last
logto = /home/laststatement/log/uwsgi.log

這是 uWSGI 日誌:

machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/apps-enabled
detected binary path: /usr/bin/uwsgi-core
uWSGI running as root, you can use --uid/--gid/--chroot options
setuid() to 1000
your processes number limit is 3750
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 TCP address 127.0.0.1:8000 fd 3
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 436752 bytes (426 KB) for 5 cores
*** Operational MODE: preforking ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!
no request plugin is loaded, you will not be able to manage requests.
you may need to install the package for your language of choice, or simply load it with --plugin.
!!!!!!!!!!! END OF WARNING !!!!!!!!!!
spawned uWSGI master process (pid: 834)
spawned uWSGI worker 1 (pid: 838, cores: 1)
spawned uWSGI worker 2 (pid: 839, cores: 1)
spawned uWSGI worker 3 (pid: 840, cores: 1)
spawned uWSGI worker 4 (pid: 841, cores: 1)
spawned uWSGI worker 5 (pid: 842, cores: 1)
-- unavailable modifier requested: 0 --
announcing my loyalty to the Emperor...
-- unavailable modifier requested: 0 --
announcing my loyalty to the Emperor...

您顯然正在執行 2 個不同的 uWSGI 版本。一個在 virtualenv 中嵌入了 python 外掛,一個在系統範圍內沒有載入 python 外掛:

!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!! no request plugin is loaded, you will not be able to manage requests. you may need to install the package for your language of choice, or simply load it with --plugin. !!!!!!!!!!! END OF WARNING !!!!!!!!!!

只需安裝 uwsgi python 外掛並使用 plugin = python 啟用它

引用自:https://serverfault.com/questions/640364