簡體   English   中英

為什么導入機械化會破壞我的AWS EC2彈性豆莖燒瓶“ Hello World” Python應用程序?

[英]Why does import mechanize break my aws ec2 elastic beanstalk flask “hello world” python app?

我可以使用這個設置ec2和flask的不錯的教程進入“ hello world”。

這是我的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並導入機械化。

我需要在教程中制作一個名為requirements.txt的文件。 這可能與我的問題有關嗎? 我需要修改嗎?

Flask==0.9

編輯:我意識到了一些。 我登錄到ec2時通過sudo pip install mechanize安裝了機械化。 我確實可以在此之后從python命令行導入機械化。 另一方面,我剛剛意識到我無法在python命令行上導入flask。

這令人困惑,顯然與我的誤解有關。

flask以前在網頁上工作過,曾經用來顯示我的“ hello world”,但是以某種方式在我登錄時並未通過python將其安裝在ec2命令行上。因此,通過python和web可用的軟件包之間存在差異ec2控制台上的python。

看起來您的python運行時環境在python控制台和您的應用之間可能有所不同。 嘗試打印出sys.path並比較差異。 sys.path初始化為PYTHONPATH。 因此,您可能需要修復/附加到此環境變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM