python - import flask on wsgi virtual host fails -
having following directory structure , setup:
. ├── 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 app import app 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__) 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 </directory> #alias /static /var/www/otherstuff/myapp/static #<directory /var/www/otherstuff/myapp/static> # order allow,deny # allow #</directory> errorlog /var/www/logs/myapp-error.log loglevel warn customlog /var/www/logs/myapp-access.log combined </virtualhost>
i can't seem figure out, why flask
dependency not loaded , therefore, fails run
mod_wsgi (pid=19668): target wsgi script '/var/www/otherstuff/myapp/myapp.wsgi' cannot loaded 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/ app import app application, referer: http://local.myapp.com/ file "/var/www/otherstuff/myapp/app/__init__.py", line 1, in <module>, referer: http://local.myapp.com/ flask import flask, referer: http://local.myapp.com/ importerror: no module named flask, referer: http://local.myapp.com/
update
flask
virtualenv:
flask/ ├── bin ├── include ├── lib ├── lib64 -> /home/alexb/www/otherstuff/faqcolab/flask/lib ├── local └── pyvenv.cfg
you need tell mod_wsgi how find packages in virtual environment. i'm not positive have folder structure correct, should this.
wsgipythonpath /var/www/otherstuff/myapp:/var/www/otherstuff/myapp/flask/lib/python2.7/site-packages
Comments
Post a Comment