我到处都在寻找解决方案,并尝试了所有答案,但似乎无济于事。我安装了redhat linux 7.5和httpd,试图在其上运行Flask应用程序。我执行了以下命令来进行设置:
# yum install httpd
然后使用以下命令安装pip:
# subscription-manager repos --enable rhel-server-rhscl-7-rpms
# yum install python27-python-pip -y
# scl enable python27 bash
# pip install --upgrade pip
然后我安装了烧瓶:
# pip install flask
和mod_wsgi:
# yum install mod_wsgi
注意:默认的python安装是python 2.7.13,这是操作系统的默认安装。
然后我将以下配置添加到“ etc / httpd / conf / httpd.conf”中的httpd.conf文件中:
<VirtualHost *:80>
ServerAdmin root@localhost
WSGIScriptAlias / /var/www/test-flask/test-flask.wsgi
WSGIScriptReloading On
<Directory /var/www/test-flask/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
这是我的.wsgi文件的样子:
import sys
sys.path.insert(0,"/var/www/test-flask/")
from test import app as application
其中“ test”是我的“ test.py”,其中flask应用程序位于我的“ test-flask”项目中。
当我检查httpd error_log时,出现以下错误:
[Sat Sep 22 17:22:04.136222 2018] [:error] [pid 15949] [client ::1:36020] mod_wsgi (pid=15949): Target WSGI script '/var/www/test-flask/test-flask.wsgi' cannot b$
[Sat Sep 22 17:22:04.136254 2018] [:error] [pid 15949] [client ::1:36020] mod_wsgi (pid=15949): Exception occurred processing WSGI script '/var/www/test-flask/te$
[Sat Sep 22 17:22:04.136265 2018] [:error] [pid 15949] [client ::1:36020] Traceback (most recent call last):
[Sat Sep 22 17:22:04.136285 2018] [:error] [pid 15949] [client ::1:36020] File "/var/www/test-flask/test-flask.wsgi", line 2, in <module>
[Sat Sep 22 17:22:04.136324 2018] [:error] [pid 15949] [client ::1:36020] from flask import Flask
[Sat Sep 22 17:22:04.136335 2018] [:error] [pid 15949] [client ::1:36020] ImportError: No module named flask
我还注意到,直到每次打开与服务器的会话时执行此命令,pip才起作用:
# scl enable python27 bash
我找不到wsgi无法读取已安装的flask软件包的原因。谁能帮忙吗?
非常感谢。