[英]Setting up a Flask app in a Amazon EC2 instance, getting ImportError: No module named flask
我在嘗試在 Amazon EC2 服務器上部署 Flask 應用程序時遇到問題。
當我去運行我的服務器時,在執行sudo apachect1 restart
后,導航到我的 ec2 站點時出現 500 內部錯誤。 檢查日志我收到以下錯誤。
[Tue Jun 20 19:10:48.429468 2017] [wsgi:error] ImportError: No module named flask, referer: http://ec2-<MY-EC2-URL>.amazonaws.com/
盡管如此,通過我用來訪問 EC2 實例的 PuTTY,我可以看到安裝了 Python 和 Flask...
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.__version__
'0.12.2'
我認為/閱讀它可能是找不到我的 Python 路徑的問題。 所以我在我的 apache 配置文件中添加了python-path=/usr/lib/python2.7
....
000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
WSGIDaemonProcess leu threads=5 python-path=/usr/lib/python2.7
WSGIScriptAlias / /var/www/html/leu/app.wsgi
<Directory leu>
WSGIProcessGroup leu
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
然而仍然沒有運氣。 我在設置虛擬環境方面見過很多,但我還沒有這樣做。 我最初使用 Python 3.5 在 PyCharm 中創建了該項目,但后來我返回了項目設置並使用 Python 2.7 創建了它並添加了所有相應的導入。 當我這樣做時仍然沒有運氣。
我應該用 virtualenv 重新啟動嗎? 設置 Apache 時我缺少什么嗎?
應用程序.wsgi
import sys
sys.path.insert(0, 'var/www/html/leu')
from app import app as application
有什么幫助嗎?
編輯:還嘗試將上面我的 Apache 配置文件中的 Python 路徑更改為/usr/local/lib/python2.7
但仍然沒有運氣
我知道我來得太晚了......希望這對正在掙扎的人有用!
ServerName your EC2 instance
你必須提到你的 EC2 實例
使用 sudo -H 安裝您的模塊。例如 sudo -H pp install flask 如果仍然存在,那么您必須更改配置以使用 python 2.7 而不是 python3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.