无法将目标 WSGI 脚本加载为 Python 模块 Raspberry Pi

Target WSGI script cannot be loaded as Python module Raspberry Pi

我正在使用 raspberry pi 与 debian linux mod_wsgi 和烧瓶。我使用本教程设置了所有内容,如果我 运行 命令

,python 脚本将 运行
python myFile.py

但是,当我尝试从 apache 运行 它时,出现 HTTP 500 错误。

这是我的 wsgi 文件:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)

sys.path.insert(0,'/var/www/FlaskApp/')

from FlaskApp import app as application

这是我的 .conf 文件:

<VirtualHost *:80>
                ServerName (my-server-ip)
                ServerAdmin (my-Email)
                WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/FlaskApp/FlaskApp/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这些是 wsgi 文件的权限

-rw-r--r-- 1 root root  211 Jul 30 18:51 flaskapp.wsgi

我看了很多不同的教程,但还没有找到解决方案...

我确定我没有 运行 为我的 python 文件设置虚拟环境,我知道这可能是个问题,但不确定如何解决。提前感谢您的帮助。

这是我得到的错误:

[Mon Jul 31 17:09:29.367693 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] mod_wsgi (pid=2921): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module.
[Mon Jul 31 17:09:29.367924 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] mod_wsgi (pid=2921): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'.
[Mon Jul 31 17:09:29.368074 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] Traceback (most recent call last):
[Mon Jul 31 17:09:29.368221 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373]   File "/var/www/FlaskApp/flaskapp.wsgi", line 8, in <module>
[Mon Jul 31 17:09:29.368643 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373]     from FlaskApp import app as application
[Mon Jul 31 17:09:29.368793 2017] [wsgi:error] [pid 2921:tid 1971319856] [client :62373] ImportError: No module named FlaskApp

这个答案来自 Graham Dumpleton:

使用python2时,项目文件夹中必须有一个名为__init__.py的文件!在我的例子中,该文件夹的路径恰好是 /var/www/FlaskApp/FlaskApp.