我已经在 vscode 终端中安装了我想使用的所有 python 库,但是当我调用 import 时,它不起作用

问题描述 投票:0回答:3
[{
    "resource": "/d:/Users/Home/Desktop/Python/estudos/pratices.py",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": {
        "value": "reportMissingModuleSource",
        "target": {
            "$mid": 1,
            "external": "https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingModuleSource",
            "path": "/microsoft/pyright/blob/main/docs/configuration.md",
            "scheme": "https",
            "authority": "github.com",
            "fragment": "reportMissingModuleSource"
        }
    },
    "severity": 4,
    "message": "Import \"pandas\" could not be resolved from source",
    "source": "Pylance",
    "startLineNumber": 1,
    "startColumn": 8,
    "endLineNumber": 1,
    "endColumn": 14
}]

是给出的消息 cmd shell 告诉我我已经安装了所有我想要安装的库,它们位于项目文件夹中,我正在运行虚拟环境,但是每当我尝试在 .py 文件中运行某些内容时,它都会说它未定义,我已经安装了 anaconda 但现在不想使用它,如果我打开一个 jupyter 文件,导入没有问题,但尝试运行 pip 根本不起作用

重新安装 vscode,确保安装了 python,确保安装了 pip

python visual-studio-code pip
3个回答
0
投票

我之前也遇到过类似的问题,我找到的解决方案是,你必须确保当前 VSC 窗口的 python 解释器是你的虚拟环境,而不是系统范围的 python 解释器。在 Windows 上:

  • 按F1
  • 搜索“口译员”。
  • 单击 python
  • 单击“输入解释器路径”。
  • 最终找到您的虚拟环境。

0
投票

您应该确保当前的解释器和安装的

pandas
库是相同的解释器环境。

可以通过以下代码输出当前解释器。

import sys
print(sys.executable)

然后使用生成的解释器路径安装

pandas
库。

<the path obtained above> -m pip install pandas


0
投票

我在 vscode 上导入了 python 项目,但它在终端上买了这个错误,我该怎么办,

$ :术语“$”不被识别为 cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者路径是否正确 已包含,请验证路径是否正确,然后重试。 在行:1 字符:1

  • $ pip 安装 pytz
  • ~
    • 类别信息:ObjectNotFound:($:字符串)[],CommandNotFoundException
    • FullyQualifiedErrorId:CommandNotFoundException
© www.soinside.com 2019 - 2024. All rights reserved.