我正在嘗試運行一個燒瓶代碼,該代碼將上傳一個 excel 檔案并在我的本地瀏覽器上顯示其內容。這是代碼:
from flask import Flask,render_template,request
import os
import pandas as pd
app=Flask(__name__)
app.secret_key="123"
app.config["UPLOAD_FOLDER1"]="static/excel"
@app.route("/display",methods=['GET','POST'])
def upload():
if request.method == 'POST':
upload_file = request.files['upload_excel']
if upload_file.filename != '':
file_path = os.path.join(app.config["UPLOAD_FOLDER1"], upload_file.filename)
upload_file.save(file_path)
data=pd.read_excel(upload_file)
return render_template("ExcelFile.html",data=data.to_html(index=False).replace('<th>','<th style="text-align:center">'))
return render_template("UploadExcel.html")
if __name__=='__main__':
app.run(debug=True)
現在,當我在 VS Code 上運行它時,會彈出此錯誤:ModuleNotFoundError: No module named 'pandas'
這是 VS Code 的問題選項卡中的錯誤訊息:Import "pandas" could not be resolved from sourcePylance(reportMissingModuleSource)
我嘗試了多種解決方案,我將在此處列出:
- “點安裝輪”
- “點安裝熊貓——升級”
- 重啟 VS 代碼
- 在我的設備中卸載并重新安裝 python
沒有任何效果。全部顯示“要求已滿足”。如果有幫助,我的解釋器是 Python 3.10.4 64 位。幫助!提前致謝!
uj5u.com熱心網友回復:
您是否嘗試過卸載并重新安裝熊貓?你也可以試試
pip install --upgrade --force-reinstall pandas
如果您在 venv 中作業,請確保您正在安裝到 venv 而不僅僅是系統庫。
uj5u.com熱心網友回復:
您提到解釋器是(Python 3.10.4 64 位)。這讓我覺得您使用的不是 venv 解釋器,而是全域解釋器。你確定你在 vscode 中使用了正確的解釋器嗎?
你提到你正在安裝到一個venv。但也許解釋器沒有在 vscode 中設定。
檢查此以選擇解釋器:
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/465515.html
上一篇:如何解決“無法將'System.Text.RegularExpressions.Match'型別的物件轉換為'System.IConvertible”。錯誤
