VS 代码:ModuleNotFoundError:没有名为“pandas"的模块 [英] VS Code: ModuleNotFoundError: No module named 'pandas'

查看:251
本文介绍了VS 代码:ModuleNotFoundError:没有名为“pandas"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 VS Code 中导入 pandas

Tried to import pandas in VS Code with

import pandas

得到

Traceback (most recent call last):
  File "c:\Users\xxxx\hello\sqltest.py", line 2, in <module>
    import pandas
ModuleNotFoundError: No module named 'pandas'

尝试用

pip install pandas

pip3 install pandas

python -m pip install pandas

分别返回

(.venv) PS C:\Users\xxxx\hello> pip3 install pandas

Requirement already satisfied: pandas in c:\users\xxxx\hello\.venv\lib\site-packages (1.1.0)
Requirement already satisfied: pytz>=2017.2 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.15.4 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (1.19.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\xxxx\hello\.venv\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in c:\users\xxxx\hello\.venv\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)

尝试过:

sudo pip install pandas

得到

(.venv) PS C:\Users\xxxx\hello> sudo pip install pandas

sudo : The term 'sudo' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ sudo pip install pandas
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (sudo:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我还尝试在这个答案之后更改工作区设置下的python路径.使用 C:\Users\xxxx\AppData\Local\Microsoft\WindowsApps\python.exe 这是我在命令提示符中使用 where python 但没有找到的 python 路径工作.

I also tried to change the python path under workspace settings following this answer. with C:\Users\xxxx\AppData\Local\Microsoft\WindowsApps\python.exe which is the python path I found in Command Prompt using where python but didn't work.

然后我尝试了

python -m venv .venv

返回的

(.venv) PS C:\Users\xxxx\hello> python -m venv .venv

Error: [Errno 13] Permission denied: 'C:\\Users\\xxxx\\hello\\.venv\\Scripts\\python.exe'


更新:


Update:

尝试过

python3.8.5 -m pip install pandas

并返回

(.venv) PS C:\Users\xxxx\hello> python3.8.5 -m pip install pandas

python3.8.5 : The term 'python3.8.5' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python3.8.5 -m pip install pandas
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (python3.8.5:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

推荐答案

解决方案看起来相当简单!不过,首先要做的事情!

The solution seems fairly simple! First things first though!

从您的帖子来看,您似乎遵循了安装 Pandas 的指南.这没什么不对,但我必须首先根据您提供给我们的信息指出,您似乎在运行 Windows Powershell PS C:\Users\xxxx\hello>错误格式与 Powershell 匹配.因此,sudo 不被认可,因为sudo基于Unix 系统(如)的管理命令Debian、Ubuntu 等 这就是为什么它不是有效命令的原因!

From looking at your post, you seem to have followed a guide into installing Pandas. Nothing is wrong about that but I must point out first based on your information that you provided to us, you seem to run Windows Powershell PS C:\Users\xxxx\hello> and the error format matches Powershell. Therefore, sudo isn't recognized because sudo is the admin command for Unix-based systems like Debian, Ubuntu, and so on which is why it's not a valid command!

但这里是正确安装的方法:(我假设您运行的是 Windows,但如果不是这种情况,请纠正我,我会给您 Unix 版本!)

But here's how to properly install: (I assume you're running Windows but if that's not the case, correct me and Ill give you the Unix version!)

1 - Windows 键,搜索 CMD 并以 administrator 运行它,这对于避免权限问题很重要!

1 - Windows key, search up CMD and run it as administrator this is important to avoid permissions issues!

2 - 运行 pip3 install pandas OR python3 -m pip3 install pandas

这篇关于VS 代码:ModuleNotFoundError:没有名为“pandas"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆