【问题标题】:Why does import mechanize break my aws ec2 elastic beanstalk flask "hello world" python app?为什么 import mechanize 会破坏我的 aws ec2 elastic beanstalk 烧瓶“hello world”python 应用程序?
【发布时间】:2014-09-13 02:46:14
【问题描述】:

我能够使用this nice tutorial 进入“hello world”以设置 ec2 和烧瓶。

这是我的application.py

import flask
#import mechanize

application = flask.Flask(__name__)

#Set application.debug=true to enable tracebacks on Beanstalk log output.
#Make sure to remove this line before deploying to production.
application.debug=True

@application.route('/')
def hello_world():
    return "Hello world!"

if __name__ == '__main__':
    application.run(host='0.0.0.0', debug=True)

取消注释 import mechanize 导致内部服务器错误 500

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

在 aws ec2 的控制台中,我确实可以运行 python 并导入 mechanize。

我需要在教程中创建一个名为 requirements.txt 的文件。这可能与我的问题有关吗?我需要修改这个吗?

Flask==0.9

编辑: 我意识到了一些事情。我在登录 ec2 时通过 sudo pip install mechanize 安装了 mechanize。在此之后,我确实可以从 python 命令行导入 mechanize。另一方面,我刚刚意识到我无法在 python 命令行上导入flask。

这令人费解,显然与我的误解有关。

flask 以前在网页上工作,用于显示我的“hello world”,但不知何故,当我登录时,它没有通过 python 安装在 ec2 命令行上。因此,通过web python和ec2控制台上的python。

【问题讨论】:

    标签: python amazon-web-services amazon-ec2 mechanize


    【解决方案1】:

    看起来你的 python 运行时环境在 python 控制台和你的应用程序之间可能不同。尝试打印出 sys.path 并比较差异。 sys.path 被初始化为 PYTHONPATH。所以你可能需要修复/附加到这个环境变量。

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 2021-02-21
      • 2017-06-07
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2021-02-25
      • 2011-05-06
      相关资源
      最近更新 更多