Home > Mobile >  ModuleNotFoundError: No module named 'pandas' in Visual Studio Code
ModuleNotFoundError: No module named 'pandas' in Visual Studio Code

Time:04-26

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!

CodePudding user response:

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.

CodePudding user response:

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: enter image description here

  • Related