寶慕林4294392
2022-10-11 16:05:35
下面是我的燒瓶代碼、文件夾結(jié)構(gòu)和錯(cuò)誤回溯。我沒(méi)有收到名為 Flask 的模塊錯(cuò)誤`from flask import render_template, request, jsonifyimport Flaskimport numpy as npimport tracebackimport pickleimport pandas as pd# App definitionapp = Flask(__name__,template_folder='templates')# importing modelswith open('C:/Users/xyz/Temp_Pred/temp_pred.pkl', 'rb') as f: regressor = pickle.load (f)with open('C:/Users/xyz/Temp_Pred/lm_columns_columns.pkl', 'rb') as f: model_columns = pickle.load (f)@app.route('/')def welcome(): return "Temperature Prediction"@app.route('/predict', methods=['POST','GET'])def predict(): if Flask.request.method == 'GET': return "Prediction page" if Flask.request.method == 'POST': try: json_ = request.json print(json_) query_ = pd.get_dummies(pd.DataFrame(json_)) query = query_.reindex(columns = model_columns, fill_value= 0) prediction = list(regressor(query)) return jsonify({ "prediction":str(prediction) }) except: return jsonify({ "trace": traceback.format_exc() })if __name__ == "__main__": app.run()Traceback 錯(cuò)誤語(yǔ)句 ` (base) C:\Users\xyz>cd C:\Users\xyz\Temp_Pred\myflaskenv\Scripts(基礎(chǔ))C:\Users\xyz\Temp_Pred\myflaskenv\Scripts>activate(myflaskenv) (基礎(chǔ)) C:\Users\xyz\Temp_Pred\myflaskenv\Scripts>cd C:\Users\xyz\Temp_Pred但是版本 20.0.2 可用。您應(yīng)該考慮通過(guò)“python -m pip install --upgrade pip”命令進(jìn)行升級(jí)。(myflaskenv) (base) C:\Users\xyz\Temp_Pred>set FLASK_APP=app.py(myflaskenv) (base) C:\Users\xyz\Temp_Pred>set FLASK_ENV=development(myflaskenv) (base) C:\Users\xyz\Temp_Pred>flask run * Serving Flask app "app.py" (延遲加載) * Environment: development * Debug mode: on * Restarting with stat * Debugger is active!* 調(diào)試器 PIN:239-673-122 * 在http://127.0.0.1:5000/上運(yùn)行(按 CTRL+C 退出)127.0.0.1 - - [15/Apr/2020 10:55:33] "[35m [1mGET / HTTP/1.1[0m” 500 - Traceback(最近一次調(diào)用最后一次):文件“C:\Users\xyz\Temp_Pred\app.py”,第 2 行,在 import Flask ModuleNotFoundError: No module named 'Flask'
1 回答

慕哥9229398
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
歡迎來(lái)到 Flask 開(kāi)發(fā)!
如評(píng)論中所述,您想要from flask import Flask
.
說(shuō)明:flask
是一個(gè)模塊(通過(guò)安裝pip
),您要從中使用類(lèi)Flask
此外,在您的路線中,您需要更改if Flask.request.method ==
為if app.request.method ==
說(shuō)明:在app=Flask()
您創(chuàng)建的對(duì)象 - 類(lèi)的實(shí)例中Flask
,從這一點(diǎn)開(kāi)始,您將始終引用該對(duì)象
另外,我建議您將帖子重命名為No module named 'Flask' error 之類(lèi)的內(nèi)容,這樣可以更好地解釋您的問(wèn)題,并且可以幫助未來(lái)的開(kāi)發(fā)人員。
添加回答
舉報(bào)
0/150
提交
取消