[英]Why pandas module is not being available while using ms-python extension in VS Code
I am new to VS Code for python. Earlier I was using spyder and it was working great.我是 python 的 VS Code 新手。之前我使用的是 spyder,它运行良好。 However, when I moved the below code base from spyder to VS Code and installed ms-python as extension, it did not work.
但是,当我将以下代码库从 spyder 移动到 VS Code 并安装 ms-python 作为扩展时,它不起作用。
Below is the code snippet for py file named test.py
下面是名为
test.py
的 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.但是,当我使用 spyder 时,上面的代码工作正常。 My local machine
python --version
is 3.8.我的本地机器
python --version
是 3.8。 As per this , ms-python
should support the local machine version.按照这个,
ms-python
应该支持本地机器版本。
The moment I switch to anaconda python interpreter in VS code, things are working fine.当我在 VS 代码中切换到 anaconda python 解释器时,一切正常。
Any clue on this?有什么线索吗?
By default, the Python extension looks for and uses the first Python interpreter it finds in the system path.默认情况下,Python 扩展查找并使用它在系统路径中找到的第一个 Python 解释器。 It might be that you have multiple Python versions installed.
可能是您安装了多个 Python 版本。
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 .您可以使用
python3 -m venv /path/to/new/virtual/environment
创建一个新环境(参见https://code.visualstudio.com/docs/python/environments ),然后使用 select Interpreter 命令并单击 Enter解释器路径或手动指定 Python 路径。
If you are on windows: in your vs codes terminal type如果你在 windows: 在你的 vs 代码终端类型
pip install pandas
pip 安装 pandas
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.