- 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
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
orpython --version
To check which interpreter VSCode is using:
>python: select interpreter
This should solve the problem.
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 commandPython: 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 justpip
whenever you need to install a package.