I’ve been following Sentdex’ Flask tutorial. He’s using a Venv to set up his Flask, but didn’t set his Python up to work with a Venv. I’ve tried installing Flask globally – yet it still doesn’t work. Trying to browse to the server returns a 500 Internal Server Error
I’m getting the usual no module named flask
error.
errorFGL.log
JavaScript
x
9
1
[Sun Feb 05 11:22:32.043925 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] mod_wsgi (pid=26340): Target WSGI script '/var/www-fgl/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
2
[Sun Feb 05 11:22:32.044105 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] mod_wsgi (pid=26340): Exception occurred processing WSGI script '/var/www-fgl/FlaskApp/flaskapp.wsgi'.
3
[Sun Feb 05 11:22:32.044243 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] Traceback (most recent call last):
4
[Sun Feb 05 11:22:32.045011 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] File "/var/www-fgl/FlaskApp/flaskapp.wsgi", line 8, in <module>
5
[Sun Feb 05 11:22:32.045070 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] from FlaskApp import app as application
6
[Sun Feb 05 11:22:32.045549 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] File "/var/www-fgl/FlaskApp/FlaskApp/__init__.py", line 1, in <module>
7
[Sun Feb 05 11:22:32.045594 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] from flask import Flask
8
[Sun Feb 05 11:22:32.045689 2017] [wsgi:error] [pid 26340:tid 118578538694400] [client 86.52.205.25:49814] ImportError: No module named 'flask'
9
__init__.py
JavaScript
1
11
11
1
from flask import Flask
2
3
app = Flask(__name__)
4
5
@app.route('/')
6
def homepage():
7
return "Success"
8
9
if __name__ == "__main__":
10
app.run()
11
flaskapp.wsgi
JavaScript
1
10
10
1
#!/usr/bin/python
2
import sys
3
import logging
4
logging.basicConfig(stream=sys.stderr)
5
6
sys.path.insert(0,"/var/www-fgl/FlaskApp/")
7
8
from FlaskApp import app as application
9
application.secret_key = '[REDACTED]'
10
fgl-database.conf
JavaScript
1
19
19
1
<VirtualHost *:80>
2
ServerName [REDACTED]
3
WSGIScriptAlias / /var/www-fgl/FlaskApp/flaskapp.wsgi
4
<Directory /var/www-fgl>
5
Require all granted
6
</Directory>
7
Alias /static /var/www-fgl/FlaskApp/FlaskApp/static
8
<Directory /var/www-fgl/FlaskApp/FlaskApp/static/>
9
Require all granted
10
</Directory>
11
ErrorLog ${APACHE_LOG_DIR}/errorFGL.log
12
LogLevel warn
13
CustomLog ${APACHE_LOG_DIR}/accessFGL.log combined
14
15
16
17
18
</VirtualHost>
19
Advertisement
Answer
As is polite behaviour when finding the solution, I googled around a bit more, and somehow managed to find a solution from a YouTube commment by Nathan Nichols here:
- Edit
/etc/apache2/sites-available/FlaskApp.conf
Add the following two lines before the “WSGIScriptAlias” line:
JavaScript131WSGIDaemonProcess FlaskApp python-path=/var/www/FlaskApp:/var/www/FlaskApp/FlaskApp/venv/lib/python2.7/site-packages
2WSGIProcessGroup FlaskApp
3
- Restart Apache with “service apache2 restart”
I of course replaced the Python version with python3.5, which is what I’m running.