Visual Studio 代码窗口,Python Pandas。没有名为 pandas 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52388154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:06:24  来源:igfitidea点击:

Visual Studio Code windows , Python Pandas . No module named pandas

pythonwindowsvisual-studiopandaspython-3.7

提问by Davdei

I set the variables for Env. All necessary modules for Pandas operation are installed by pip. I wanted to run the code to display it in "Output". I run with: Alt + CTRL + N(or right click -> Run code).

我为 Env 设置了变量。Pandas 操作所需的所有模块都由 pip 安装。我想运行代码以在“输出”中显示它。我运行:Alt + CTRL + N(或右键单击 -> 运行代码)。

enter image description here

在此处输入图片说明

In output returns the message:

在输出中返回消息:

enter image description here

在此处输入图片说明

But when I run in the terminal (right click -> Run Python File in Terminal), the code works correctly.

但是当我在终端中运行时(右键单击 -> 在终端中运行 Python 文件),代码运行正常。

enter image description here

在此处输入图片说明

I would like the code to run correctly in output(right click -> Run code), not in the terminal. Any suggestions?

我希望代码在输出中正确运行(右键单击 -> 运行代码),而不是在终端中。有什么建议?

采纳答案by Mohammad Zain Abbas

It seems that the module pandasis installed in a virtual envorinment which you are not accessing via VS Code.

似乎模块pandas安装在您没有通过VS Code访问的虚拟环境中。

I'd suggest you to install pandasin default python as well via

我建议您也通过以下方式在默认 python 中安装 Pandas

pip install pandas

This way the VS Code will work it out just fine.

这样 VS Code 就能很好地解决问题。

Else:

别的:

In VS Code console, activatethe virtual enviornmentin which you have installed the pandasmodule, and then runit. It should work

VS Code 控制台中激活安装了pandas模块的虚拟环境,然后运行它。它应该工作

回答by Feras

@Davdei It is good practice to work with a virtual environment, so you can test against different versions of Python. To get the list of available Python interpreter use (??P) on Mac or alternatively, you can click the status bar click the status bar

@Davdei 使用虚拟环境是一种很好的做法,因此您可以针对不同版本的 Python 进行测试。要获取 Mac 上可用 Python 解释器使用 (??P) 的列表,或者,您可以单击状态栏 点击状态栏

回答by Sri Vishal Sivasubramanian

This can also happen when the specific module is not installed using pip3, so simply installing the module using pip3 would solve the problem.

当未使用 pip3 安装特定模块时也会发生这种情况,因此只需使用 pip3 安装模块即可解决问题。

pip3 install pandas

回答by Martin

I had a similar problem in VS Code. I was not able to find modules like Pandas, Selenium etc. Imports were underlined with a red colour.

我在 VS Code 中遇到了类似的问题。我找不到像 Pandas、Selenium 等模块。进口用红色下划线标出。

Fixed the issue by changing the version of Python3.7.3 64-bitto version 3.8.1 64-bit.

通过改变版本修正了这个问题的Python3.7.3 64-bit到版本3.8.1 64-bit

Procedure:

程序:

  1. Hit Ctrl + Shift + P
  2. Select Python: Select Interpreter
  3. Choose the latest installed version of Python (no more red underlines)
  1. Ctrl + Shift + P
  2. 选择 Python:选择解释器
  3. 选择最新安装的 Python 版本(不再有红色下划线)