简体   繁体   English

为什么在 VS Code 中使用 ms-python 扩展时 pandas 模块不可用

[英]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.

相关问题 VSCode 中的交互式 Jupyter 小部件与 ms-python 2018.10.1 - Interactive Jupyter widgets in VSCode with ms-python 2018.10.1 如何防止 vscode/ms-python 清除测试结果? - How to prevent vscode/ms-python from clearing test results? 使用 python 标准库网络浏览器的 VS 代码中的 Python 脚本仅在使用调试器扩展时才有效 - Python script in VS code using python standard library webbroswer works only while using debugger extension 为什么在 python 的 vs 代码中没有导入街机模块 - why there is no import of arcade module in vs code for python 为什么 VS 代码显示使用 abc 模块的 python 代码语法无效 - python3.8.0 - Why VS code shows it's invalid syntax for a python code using abc Module - python3.8.0 vs代码的python扩展 - python extension for vs code 使用 Python 扩展时在 VS Code 中查看 Ipython Notebooks 的基于行的差异 - Viewing Ipython Notebooks' line based diff in VS Code while using the Python extension VSCode:使用MS Python扩展无法执行代码 - VSCode: Using the MS Python extension cannot execute code 使用 python 日志模块的 vs 代码中没有 output - no output in vs code using python logging module 如何让 ms-python 识别未直接使用 pip 安装的软件包 - How to get ms-python to recognize packages that were not installed directly with pip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM