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 -
See the bottom of this page: https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/#configuring-apache
Were it says:
For Python 3 add the following lines to the top of your .wsgi file:
activate_this = '/path/to/env/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
Where /path/to/env is the path to any virtual environment where you installed Flask, as described by others here on this thread. The "python-path" and some of the other VirtualHost configurations described here are unnecessary.
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
Source: https://vishnut.me/blog/ec2-flask-apache-setup.html
According to http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html.
You should edit /etc/apache2/sites-available/FlaskApp.conf
Add these above the WSGIScriptAlias
WSGIDaemonProcess FlaskApp python-home=/var/www/FlaskApp/FlaskApp/venv/FlaskApp
WSGIProcessGroup FlaskApp
I met the same problem and fix it by the way.
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:
https://www.digitalocean.com/community/tutorials/how-to-run-django-with-mod_wsgi-and-apache-with-a-virtualenv-python-environment-on-a-debian-vps
/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-packages
WSGIProcessGroup FlaskApp
I of course replaced the Python version with python3.5, which is what I'm running.
Nothing worked for me, but I just add below line in starting of my .py and .wsgi file voila it worked:
import sys
sys.path.append('/home/ubuntu/pythonVirtual/lib/python3.6/site-packages)
here pythonVirtual
is my virtual directory for Python
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-packages
WSGIProcessGroup FlaskApp
Add above lines in FlaskApp.conf in sites-available directory of apache
Note put python-path what you get after running pip --version