Home > Mobile >  ModuleNotFoundError in VS code with Jupyter note book but not .py files
ModuleNotFoundError in VS code with Jupyter note book but not .py files

Time:10-03

I am using visual studio code on windows, and I am trying to run a python code on jupyter-notebook. I have all packages installed and they work fine when it is a normal python file. But I need it to run as a notebook. Once I run the block, I immediately get the following error:

ModuleNotFoundError                       Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5668\1439934476.py in <module>
      1 import csv
----> 2 from pandas import read_csv
      3 from matplotlib import pyplot as plt
      4 import numpy as np
      5 import os

ModuleNotFoundError: No module named 'pandas'

I made sure that requirements are already satsified for this module, and I already tried running this line in python file with no issues. Therefore, how can I solve this issue? How can I let Jupyter notebook compiler to see where these packages actually are?

CodePudding user response:

First you need to install pandas by running the command in your console:

pip install pandas

If you don't have pip installed on your computer then install it, otherwise you won't be able to download pandas or other modules

PS: check that when you downloaded python you chose the add to PATH option
Hoping I could help

CodePudding user response:

The installation of pip is related to the python path specified in the environment variable. You need to select the correct interpreter in vscode.

Python is an interpreted language, and in order to run Python code and get Python IntelliSense, you must tell VS Code which interpreter to use.

From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl Shift P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too): enter image description here

Read docs for more details.

  • Related