Flask - WSGI - No module named 'flask'

后端 未结 6 838
闹比i
闹比i 2021-02-01 23:50

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 -

相关标签:
6条回答
  • 2021-02-02 00:27

    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.

    0 讨论(0)
  • 2021-02-02 00:32

    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

    0 讨论(0)
  • 2021-02-02 00:34
    1. According to http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html.

    2. You should edit /etc/apache2/sites-available/FlaskApp.conf

    3. 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.

    0 讨论(0)
  • 2021-02-02 00:43

    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

    1. Edit /etc/apache2/sites-available/FlaskApp.conf
    2. 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
      
    3. Restart Apache with "service apache2 restart"

    I of course replaced the Python version with python3.5, which is what I'm running.

    0 讨论(0)
  • 2021-02-02 00:46

    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

    0 讨论(0)
  • 2021-02-02 00:52

    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

    0 讨论(0)
提交回复
热议问题