Flask - WSGI - No module named 'flask'
I wasted about 25 minutes finding a solution to this and after following all the other resources I could find, I also did the following:
sudo apt-get install libapache2-mod-wsgi-py3
Make sure to have '-py3' at the end of libapache2-mod-wsgi-py3 or the runtime will default to Python2.7
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:
WSGIDaemonProcess FlaskApp python-path=/var/www/FlaskApp:/var/www/FlaskApp/FlaskApp/venv/lib/python2.7/site-packagesWSGIProcessGroup FlaskApp
- Restart Apache with "service apache2 restart"
I of course replaced the Python version with python3.5, which is what I'm running.
First install python-virtualenv
Then from the Flask app directory where you put the wigs python files run
virtualenv env
This will create env directory inside the Flask directory and contains the local python installation.
Next activate the virtual environment by this command source env/bin/activate
After activating the virtual environment run pip install flask
Run pip --version
You will see something like this
pip 19.0.3 from /var/www/html/flaskapp/env/local/lib/python2.7/site-packages/pip (python 2.7)
Copy this python path
WSGIDaemonProcess FlaskApp python-path=/var/www/html/flaskapp:/var/www/html/flaskapp/env/local/lib/python2.7/site-packagesWSGIProcessGroup FlaskApp
Add above lines in FlaskApp.conf in sites-available directory of apache
Note put python-path what you get after running pip --version