ModulenotFoundError:No模块名为' pandas'在Visual Studio代码中

发布于 2025-01-24 05:31:49 字数 1311 浏览 2 评论 0原文

我正在尝试运行一个可以上传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代码上运行此错误时,此错误会弹出: modulenotfounderror:no模块名为“ pandas'

这是VS代码问题选项卡中的错误消息:导入“熊猫”无法从source pylance(reportmissingmodulesource)

我尝试过多种解决方案,我将在这里列出它们:

  1. “ pip install astell wheel'
  2. “ pip install install pand pandas - upgrade - upgrade”
  3. 重新启动vs代码
  4. 卸载和重新安装和重新安装和重新安装。 Python在我的设备中

什么都没有。所有显示“需求已经满足”。 如果有帮助,我的解释器是Python 3.10.4 64位。 帮助!提前致谢!

I'm trying to run a flask code that would upload an excel file and display its contents on my local browser. This is the code :

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)

Now when I run this on VS Code, this error pops up : ModuleNotFoundError: No module named 'pandas'

This is the error message in the problem tab of VS Code : Import "pandas" could not be resolved from sourcePylance(reportMissingModuleSource)

I've tried multiple solutions, I'll list them here :

  1. "pip install wheel"
  2. "pip install pandas --upgrade"
  3. Restarting VS Code
  4. Uninstalling and reinstalling python in my device

Nothing has worked. All show "Requirement already satisfied".
My interpreter is Python 3.10.4 64-bit, if it helps.
HELP! Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掩于岁月 2025-01-31 05:31:49

您是否尝试过卸载和重新安装熊猫? 如果您在VENV中工作,也可以尝试

pip install --upgrade --force-reinstall pandas

,请确保您要安装到VENV,而不仅仅是系统库。

Have you tried uninstalling and reinstalling pandas? You could also try

pip install --upgrade --force-reinstall pandas

If you're working in a venv, make sure you're installing to the venv and not just to the system library.

始于初秋 2025-01-31 05:31:49

您提到的是解释器(Python 3.10.4 64位)。这让我觉得您不是使用VENV口译员,而是使用全球口译员。您确定在VSCODE中使用了正确的解释器吗?

您提到您正在安装到VENV。但是也许解释器未在VScode中设置为。

检查一下以选择解释器: https:https:// code。 VisualStudio.com/docs/python/environments#_work-with-python-interpreters

You mentioned the interpreter is (Python 3.10.4 64-bit). This makes me feel you are not using the venv interpreter but the global one. Are you sure you are using the correct interpreter in vscode?

You mentioned you are installing to a venv. But maybe the interpreter is not set to that in vscode.

Check this out to select the interpreter: https://code.visualstudio.com/docs/python/environments#_work-with-python-interpreters

许一世地老天荒 2025-01-31 05:31:49

您是否正确地导入大熊猫的道路?

错误消息在VS代码的问题选项卡中:导入“ PANDAS”无法从sourcepylance(reportMissingModulesource)解决,

这意味着VSCODE无法识别它。

您可以在设置中添加pandas'path。

Have you imported the path of pandas correctly?

error message in the problem tab of VS Code : Import "pandas" could not be resolved from sourcePylance(reportMissingModuleSource)

This means vscode doesn't recognize it.

You could add pandas'path in the settings manually.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文