wsgi虚拟主机上的import flask失败

时间:2015-05-15 11:00:47

标签: python apache flask wsgi

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

.
├── 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)

__初始化__。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是virtualenv:

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

1 个答案:

答案 0 :(得分:1)

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

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