wsgi 虚拟主机上的导入烧瓶失败

import flask on wsgi virtual host fails

具有以下目录结构和设置:

.
├── app
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── static
│   ├── templates
│   │   ├── base.html
│   │   └── index.html
│   ├── views.py
│   └── views.pyc
├── flask
├── myapp.wsgi
├── run.py
├── run.pyc
└── tmp

myapp.wsgi

#!/usr/bin/python
import sys, os, logging
logging.basicConfig(stream=sys.stderr)
#sys.path.insert(0,"/var/www/otherStuff/myApp/")
sys.path.insert(0, os.path.dirname(__file__))

#from app import app
from app import app as application
application.secret_key = 'xyz'

if __name__ == '__main__':
    app.run(host='0.0.0.0',debug=True)

__init__.py

from flask import Flask

app = Flask(__name__)
from app import views

vhost.conf

<VirtualHost *:80>
        ServerName local.myapp.com
        WSGIScriptAlias / /var/www/otherStuff/myApp/myappwsgi
        <Directory /var/www/otherStuff/myApp/app>
                Order allow,deny
                Allow from all
        </Directory>
        #Alias /static /var/www/otherStuff/myApp/static
        #<Directory /var/www/otherStuff/myApp/static>
        #       Order allow,deny
        #       Allow from all
        #</Directory>
        ErrorLog /var/www/logs/myApp-error.log
        LogLevel warn
        CustomLog /var/www/logs/myApp-access.log combined
</VirtualHost>

我似乎无法弄清楚,为什么 Flask 依赖项没有加载,因此 运行

mod_wsgi (pid=19668): Target WSGI script '/var/www/otherStuff/myApp/myapp.wsgi' cannot be loaded as Python module., referer: http://local.myapp.com/
mod_wsgi (pid=19668): Exception occurred processing WSGI script '/var/www/otherStuff/myApp/myapp.wsgi'., referer: http://local.myapp.com/
Traceback (most recent call last):, referer: http://local.myapp.com/
  File "/var/www/otherStuff/myApp/myapp.wsgi", line 8, in <module>, referer: http://local.myapp.com/
    from app import app as application, referer: http://local.myapp.com/
  File "/var/www/otherStuff/myApp/app/__init__.py", line 1, in <module>, referer: http://local.myapp.com/
    from flask import Flask, referer: http://local.myapp.com/
ImportError: No module named flask, referer: http://local.myapp.com/

更新

flask 是虚拟环境:

flask/
├── bin
├── include
├── lib
├── lib64 -> /home/alexb/www/otherStuff/faqColab/flask/lib
├── local
└── pyvenv.cfg

您需要告诉 mod_wsgi 如何在您的虚拟环境中查找包。我不确定您的文件夹结构是否完全正确,但应该是这样的。

WSGIPythonPath /var/www/otherStuff/myApp:/var/www/otherStuff/myApp/flask/lib/python2.7/site-packages