nginx – 在uwsgi.conf中正确指定virtualenv

我试图让一个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

任何人都可以告诉我应该将venv和pyhome设置为什么,因为我认为这是问题所在?或者实际上如果我应该同时设置两者?

同样相关的是,当我从终端运行以下命令时,我可以毫无错误地导入烧瓶模块:

$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
>>> 

我只是错误地在uwsgi.conf中设置venv?

最佳答案
你应该摆脱没有网站.根据文件:

Do not import the site module while initializing Python. This is usually only required for dynamic virtualenvs. If in doubt, do not enable.

另外,pyhome是venv的别名,所以你最好摆脱它.

仅供将来参考,venv应设置为virtualenv的顶级文件夹:/ srv / http / example / htdocs

转载注明原文:nginx – 在uwsgi.conf中正确指定virtualenv - 代码日志