Nginx

在 uwsgi.conf 中正確指定 virtualenv

  • December 26, 2013

我正在嘗試讓 uwsgi 環境在 Arch 上正常工作,以從 virtualenv 執行我的 Flask 應用程序。

我已經安裝了 uwsgi、nginx 和 virtualenv,這些都可以工作。

但是我在uwsgi日誌中看到以下錯誤:

Traceback (most recent call last):
 File "./interface.py", line 1, in <module>
   from flask import flask
ImportError: No module named flask
unable to load app 0 (mountpoint='') (callable not found or import error)
unable to find "application" callable in file index.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 4795)
spawned uWSGI worker 1 (pid: 4796, cores: 1)
--- no python application found, check your startup logs for errors ---
[pid: 4796|app: -1|req: -1/1] 192.168.9.201 () {40 vars in 664 bytes} [Thu Dec 26 08:01:56 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

這表明它無法載入燒瓶模組,我猜這是由於不正確uwsgi.conf

[uwsgi]
uid = http
gid = http
plugin = python2
socket = %drun/%n.sock
chdir = /srv/http/example/htdocs
master = True
pidfile = %drun/%n.pid
logto = %dlog/%n.log
venv = /srv/http/example/htdocs
pyhome = /srv/http/example/htdocs
module = interface
callable = my_app
no-site = true

誰能告訴我我應該設置什麼venvpyhome因為我認為這是問題所在?或者事實上,如果我應該同時設置兩者?

同樣相關的是,當我從終端執行以下命令時,我可以毫無錯誤地導入燒瓶模組:

$ pwd
/srv/http/example/htdocs
$ . bin/activate
(htdocs) $ python
Python 2.7.6 (default, Nov 26 2013, 12:52:49) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> 

我只是設置venvuwsgi.conf正確嗎?

你應該擺脫no-site. 根據文件:

初始化 Python 時不要導入站點模組。這通常只對動態 virtualenvs 是必需的。如有疑問,請勿啟用.

此外,pyhome是一個別名,venv所以你最好擺脫它。

僅供將來參考,venv應設置為您的 virtualenv 的頂級文件夾:/srv/http/example/htdocs

引用自:https://unix.stackexchange.com/questions/106732