I am trying to set up a simple flask app on an ec2 instance with apache2 server and mod_wsgi. Seem to be having disproportionate amount of diffculty configuring the correct python path for mod_wsgi to use.
I have placed code snippets below.
The error I get the apache2 log is:
Traceback (most recent call last):
File "/var/www/html/flaskapp_tut/flaskapp_tut.wsgi", line 7, in <module>
from flaskapp_tut import app as application
] File "/var/www/html/flaskapp_tut/flaskapp_tut.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
flask is definitely installed via anaconda installation, however clearly the wrong version of python is being used by mod_wsgi.
The log files says its using: apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
However I am using python 3.x, and the anaconda installation show when I use the command "which python" ie /home/ubuntu/anaconda3/bin/python
the mod_wsgi documentation says you can configure the python path with: WSGIPythonHome /home/ubuntu/anaconda3/bin/python, however I do not know where to place this configuration.
Would appreciate any assistance. This seems as though it should be a lot more straightforard than it is, according to the steps I am using as a guide: http://www.datasciencebytes.com/bytes/2015/02/24/running-a-flask-app-on-aws-ec2/
flaskapp_tut.wsgi
#!/home/ubuntu/anaconda3/bin/python
import sys
sys.path.insert(0, '/var/www/html/flaskapp_tut')
sys.path.append('/home/ubuntu/anaconda3/bin/python')
from flaskapp_tut import app as application
flaskapp_tut.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello from Flask!'
if __name__ == '__main__':
app.run()
Settings within the 000-default.conf file
DocumentRoot /var/www/html
WSGIDaemonProcess flaskapp_tut threads=5
WSGIScriptAlias / /var/www/html/flaskapp_tut/flaskapp_tut.wsgi
<Directory flaskapp_tut>
WSGIProcessGroup flaskapp_tut
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>