I am new to VS Code for python. Earlier I was using spyder and it was working great. However, when I moved the below code base from spyder to VS Code and installed ms-python as extension, it did not work.
Below is the code snippet for py file named test.py
import pandas as pd
import os
file_path = 'C:\file_path\'
file_name = 'test.xlsx'
df = pd.read_excel(os.path.join(file_path,file_name))
But I am getting error:
[ModuleNotFoundError]:Module pandas not found
However the above code works fine when I am using spyder. My local machine python --version
is 3.8. As per this , ms-python
should support the local machine version.
The moment I switch to anaconda python interpreter in VS code, things are working fine.
Any clue on this?
By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. It might be that you have multiple Python versions installed.
You can either create a new environment with python3 -m venv /path/to/new/virtual/environment
(see https://code.visualstudio.com/docs/python/environments ) and then select Interpreter command and clicking on the Enter interpreter path or manually specify Python path .
If you are on windows: in your vs codes terminal type
pip install pandas
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.