I am getting 500 internal server error when running my server with Flask,apache2, and Python 3.4.2.
At first I installed Flask without creating virtual environment, so I thought that that could be a reason. However, I later created virtual environment for my app using:
python3.4 -m venv venv
source venv/bin/activate
(venv) pip3 install Flask
I checked by running my app using python3 __init.py and it was working on local. Then I reloaded my apache2 server, and still getting the same error. Please see below output from error log file:
mod_wsgi (pid=25667): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=25667): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
Traceback (most recent call last):
File "/var/www/FlaskApp/flaskapp.wsgi", line 11, in <module>
from XYZ import app as application
File "/var/www/FlaskApp/XYZ/__init__.py", line 1, in <module>
from flask import Flask, render_template
ImportError: No module named flask
Any suggestions how to fix it?
FlaskApp.conf file in the etc/apache2/sites-available
<VirtualHost *:80>
ServerName xyz.com
ServerAlias www.xyz.com
ServerAdmin contact@xyz.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/XYZ/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/XYZ/static
<Directory /var/www/FlaskApp/XYZ/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Here's line from apache2 error log file:
AH00489: Apache/2.4.10 (Ubuntu) mod_wsgi/3.5 Python/2.7.8 configured -- resuming normal operations
It looks like mod_wsgi is trying to use 2.7.8 as opposed to 3.4. How do I fix that?