【问题标题】:VS Code: ModuleNotFoundError: No module named 'pandas'VS 代码:ModuleNotFoundError:没有名为“pandas”的模块
【发布时间】:2020-12-02 21:18:16
【问题描述】:

尝试在 VS Code 中导入pandas

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'

尝试安装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

我还尝试在this answer 之后更改工作区设置下的 python 路径。 C:\Users\xxxx\AppData\Local\Microsoft\WindowsApps\python.exe 是我在命令提示符中使用 where python 找到的 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'

更新:

试过

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

【问题讨论】:

  • 你试过python -m pip install pandas吗?还是python3.x -m pip install pandas
  • 或者以python3 file.py运行它?
  • 嗨@MZ,请查看已编辑的问题;如何以python3 file.py 运行它?
  • 在终端做python3 sqltest.py
  • 我的意思不是字面上的 python3.x。我的意思是 3.(无论你使用什么 python 版本)或者只是 python3

标签: python visual-studio-code


【解决方案1】:

我刚刚以管理员身份运行 VSCode!

【讨论】:

    【解决方案2】:

    这比我们想象的要容易:

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

    【讨论】:

      【解决方案3】:

      似乎合作过

      pip install pandas --user
      

      在命令提示符中。


      补充说明:

      对于IPython.display

      pip install IPython--user
      

      在命令提示符中,然后

      from IPython.display import display
      

      在 VS 代码中。

      有用的链接:

      pip --user

      Display() in Python

      【讨论】:

        【解决方案4】:

        解决方案似乎相当简单!不过首先要做的事情!

        通过查看您的帖子,您似乎已按照指南安装Pandas。这没有什么问题,但我必须首先根据您提供给我们的信息指出,您似乎在运行 Windows Powershell PS C:\Users\xxxx\hello&gt;the error format matches Powershell。因此,sudo 无法识别,因为 sudoUnix-based 系统(如 Debian, Ubuntu, and so on)的管理命令,这就是它不是有效命令的原因!

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

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

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

        【讨论】:

          猜你喜欢
          • 2021-07-01
          • 1970-01-01
          • 2020-09-26
          • 2022-10-18
          • 2022-01-16
          • 1970-01-01
          • 2021-02-06
          • 2020-09-02
          • 2018-05-16
          相关资源
          最近更新 更多