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

时间:2017-07-31 16:10:24

标签: python linux apache flask mod-wsgi

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

,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

1 个答案:

答案 0 :(得分:2)

这个答案来自Graham Dumpleton:

使用python 2时,项目文件夹中必须有一个名为getJson(x){ let z = x.replace(/'/g, '"'); return JSON.parse(z); } 的文件!就我而言,该文件夹的路径恰好是<div *ngFor="let city of getJson(optCities[0].resultData.Hoteloption[0].CityRating);let i = index; "> {{city.Rating}} </div>