我正在尝试在Amazon Linux AMI上运行一个简单的python烧瓶应用程序。我能够显示Amazon Linux AMI测试页面,但是当我尝试创建正确的配置来运行我的应用程序时,我面临着同样的问题。
[Fri Sep 16 12:56:39.190230 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] mod_wsgi (pid=17977): Target WSGI script '/var/www/flaskapp/app.wsgi' cannot be loaded as Python module.
[Fri Sep 16 12:56:39.190239 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] mod_wsgi (pid=17977): Exception occurred processing WSGI script '/var/www/flaskapp/app.wsgi'.
[Fri Sep 16 12:56:39.190252 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] Traceback (most recent call last):
[Fri Sep 16 12:56:39.190271 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] File "/var/www/flaskapp/app.wsgi", line 26, in <module>
[Fri Sep 16 12:56:39.190288 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] from app import app as application
[Fri Sep 16 12:56:39.190294 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] File "/var/www/flaskapp/app.py", line 1, in <module>
[Fri Sep 16 12:56:39.190303 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] from flask import Flask
[Fri Sep 16 12:56:39.190316 2016] [:error] [pid 17977] [remote 77.246.17.229:59978] ImportError: No module named flask
我的app.py:
from flask import Flask
app=Flask(__name__)
@app.route('/')
def home():
return "Hello World!"
if __name__ == "__main__":
app.run()
我的app.wsgi:
import sys
import site
import os
# Add virtualenv site packages
site.addsitedir(os.path.join(os.path.dirname(__file__), '/env/lib/python2.7/site-packages'))
activate_this = '/var/www/flaskapp/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
# Path of execution
sys.path.insert(0,'/var/www/flaskapp')
#import the app
from app import app as application
和我的httpd.conf:
<VirtualHost *>
ServerName ec2....
WSGIDaemonProcess app threads=5 home=/var/www/flaskapp/ python-path=/var/www/flaskapp/env/lib/python2.7 threads=1
DocumentRoot /var/www/flaskapp
WSGIScriptAlias / /var/www/flaskapp/app.wsgi
<Directory /var/www/flaskapp>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
如果我看看virtualenv wit pip freeze中安装了什么,我得到了这个:
click==6.6
Flask==0.11.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.11
所以安装了Flask。为什么我无法导入它?我做错了什么?
感谢
答案 0 :(得分:0)
在EC2 / EB上,通过上传zip文件,通过控制台部署烧瓶应用程序。 将烧瓶应用程序保存为PC上的普通烧瓶应用程序。我猜AWS会自动处理WSGI。
请执行以下操作:
application = app = Flask(__name__)
......
......
application.run()
将此主文件另存为“application.py”
通过AWS控制台进行压缩和上传,它将运行。
答案 1 :(得分:0)
转到/ var / www / html文件夹,然后在该目录中安装flask。 使用sudo命令相同。 然后您的应用应该可以工作,