我正在嘗試在我的燒瓶應用程式中匯入熊貓。我這樣做的那一刻,我收到了內部服務器錯誤。我在 Digital Ocean Droplet (Ubuntu 20.0.4) 上運行我的應用程式。
服務器:nginx
如果我不匯入熊貓,一切都會按預期運行。我已經通過 pip install 安裝了 pandas。請您幫我解決這個問題:)
這是片段:
from flask import Flask, render_template, url_for, request
app = Flask(__name__, template_folder="templates")
import pandas as pd
@app.route("/")
def home():
try:
return render_template('home.html')
except Exception as e:
return str(e)
if __name__ == "__main__":
app.run(host='0.0.0.0')
uj5u.com熱心網友回復:
根據我們的討論,您必須if像這樣在塊內匯入包。
...
if __name__ == "__main__":
import pandas as pd
...
由于默認開發服務器在 Flask 中的作業方式,我可能只能用有限的資訊來猜測這是否有效。有時每個請求的路由由新的衍生/分叉行程處理,當系統資源受限時,在所有行程上匯入重包可能最終占用資源限制,從而殺死行程或小程式呈現服務器錯誤。
很高興這有幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/400409.html
下一篇:Python-在回傳陳述句上縮進
