VS Code:ModuleNotFoundError:没有名为“pandas”的模块

2024-04-27

尝试导入pandas在 VS 代码中

import pandas

and got

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

尝试安装pandas with

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)

Tried:

sudo pip install pandas

and got

(.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 路径,如下所示这个答案 https://stackoverflow.com/a/54107016/11901732. with C:\Users\xxxx\AppData\Local\Microsoft\WindowsApps\python.exe这是我在命令提示符中找到的 python 路径where python但没有用。

然后我尝试了

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:

Tried

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

这比我们想象的要容易:

这张图解释了如何解决这个问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

VS Code:ModuleNotFoundError:没有名为“pandas”的模块 的相关文章