0
我試圖在亞馬遜Linux AMI上運行簡單的python flask應用程序。我能夠顯示亞馬遜Linux AMI測試頁面,但是當我嘗試創建適當的配置來運行我的應用程序時,我總是面臨同樣的問題。EC2上的Python Flask應用程序AWS
[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機智pip凍結我得到這個:
click==6.6
Flask==0.11.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.11
so Flask is installed。爲什麼我無法導入它?我做錯了什麼?
感謝
'WSGIDaemonProcess'的'python-path'輸入應指向'site-packages'目錄。 – Suever
如果我將python-path更改爲/var/www/flaskapp/env/lib/python2.7/site-packages我會從markupsafe import中得到: 標記,轉義,soft_unicode ImportError:沒有名爲markupsafe的模塊 – Thomas