我正在尝试在ec2上的RHEl 7上运行的apache上部署我的烧瓶应用程序。当我卷曲http://localhost/时,我在error_logs中得到导入错误我还在导入之前在wsgi文件中打印了sys.path 我的错误日志:
[Thu Feb 22 19:16:21.249918 2018] [:error] [pid 30698] ['/var/www/rest_api', '/var/www/rest_api', '/var/www/rest_api/venv/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']
[Thu Feb 22 19:16:21.250288 2018] [:error] [pid 30698] [remote ::1:0] mod_wsgi (pid=30698): Target WSGI script '/var/www/rest_api/example.wsgi' cannot be loaded as Python module.
[Thu Feb 22 19:16:21.250302 2018] [:error] [pid 30698] [remote ::1:0] mod_wsgi (pid=30698): Exception occurred processing WSGI script '/var/www/rest_api/example.wsgi'.
[Thu Feb 22 19:16:21.250317 2018] [:error] [pid 30698] [remote ::1:0] Traceback (most recent call last):
[Thu Feb 22 19:16:21.250335 2018] [:error] [pid 30698] [remote ::1:0] File "/var/www/rest_api/example.wsgi", line 15, in <module>
[Thu Feb 22 19:16:21.250388 2018] [:error] [pid 30698] [remote ::1:0] from run import app as application
[Thu Feb 22 19:16:21.250404 2018] [:error] [pid 30698] [remote ::1:0] ImportError: No module named run
example.wsgi:
#!/usr/bin/python
activate_this = '/var/www/rest_api/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
logging.info(sys.path)
sys.path.insert(0,"/var/www/rest_api")
print sys.path
from run import app as application
run.py:
from flask import Flask, Blueprint, request
from flask_restful import Resource, Api
from resources.insert import blueprint
from resources.get import get_blueprint
app = Flask(__name__)
app.register_blueprint(blueprint)
app.register_blueprint(get_blueprint)
if __name__ == '__main__':
app.run()
myapp.conf:
<VirtualHost *:80>
WSGIProcessGroup rest_api
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
WSGIPassAuthorization On
WSGIDaemonProcess rest_api python-path=/var/www/rest_api:/var/www/rest_api/venv/lib/python2.7/site-packages user=ec2-user group=ec2-user threads=5
WSGIScriptAlias / /var/www/rest_api/example.wsgi
<Directory /var/www/rest_api>
Require all granted
</Directory>
</VirtualHost>
我正在使用python 2.7的虚拟环境