繁体   English   中英

在 Amazon EC2 实例中设置 Flask 应用程序,得到 ImportError: No module named flask

[英]Setting up a Flask app in a Amazon EC2 instance, getting ImportError: No module named flask

我在尝试在 Amazon EC2 服务器上部署 Flask 应用程序时遇到问题。

我也跟着教程herehere

当我去运行我的服务器时,在执行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 时我缺少什么吗?

我能够获得 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM