skip to Main Content
  • MacBook Air M2
  • Visual Studio Code
  • Python 3.12.3

I installed pandas using

pip3 install pandas

and I wite code

import pandas as pd

If i run this code there is an error

ModuleNotFoundError: No module named 'pandas'

There is no error before I run the code,

But If I run the code error exist.

Also numpy has same error.

I installed it but can’t find module…

2

Answers


  1. VSCode might create a python env apart from your local python. Check if the interpreter used by VSCode and the one you are using on terminal are the same.

    To check the terminal one, use python -V or python --version

    To check which interpreter VSCode is using:

    1. Use the shortcut Ctrl/Cmd + Shift + P
    2. Type: >python: select interpreter
    3. Select, from the list, the same one that you installed and are using on the terminal.

    This should solve the problem.

    Login or Signup to reply.
  2. Do you have more than one version of Python installed? If you’re using VS Code, make sure the Python interpreter you have selected is the same one for which you installed pandas, etc..

    You can use the command py --version in the terminal to determine which Python is used when you run pip. Once you have that info, you can run the command Python: Select Interpreter from VS Code (or click on the Python version in the bottom-right corner).

    The most foolproof approach aside from that, is to run py -m pip instead of just pip whenever you need to install a package.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search