ImportError: No module named 'flask' pytho

2020-05-03 11:16发布

问题:

< mod_wsgi cannot import flask. 

I did not install flask under a virtualenv. I can import flask using a python shell just fine. I edited my virtualhost config to contain WSGIDaemonProcess HRApp user=USER group=GROUP python-path=/home/USER/.local/bin/python3.5/site-packages to no avail. What am I missing?

Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.__version__
'1.0.2'
>>>

apache config:

    WSGIDaemonProcess HRApp user=USER group=GROUP python-path=/home/USER/.local/bin/python3.5/site-packages
    WSGIScriptAlias / /path/to/file.wsgi

    <Directory /var/www/appname>
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
            AuthType Basic
            AuthName "USER"
            AuthUserFile "/passwords_file"
            Require valid-user
    </Directory>

回答1:

Solved it by installing a virtualenv in the Flask app's root folder and then pointing mod_wsgi to that as the python installation with WSGIPythonHome