为什么 python 导入在 VS 代码中不起作用?

Why is python import not working in VS code?

我下载了 pip 包 'xlrd' 来读取 excel 文件。当我尝试 运行 模块时,程序显示我还没有下载那个 pip。我无法找到答案,因为我不知道该问什么问题。我该如何解决这个问题?

下载pip时提示信息: 'Requirement already satisfied: xlrd in c:\users\thecodeadd\appdata\local\programs\python\python310\lib\site-packages (2.0.1)' 它在 'Problems' 中显示的程序内容:

[{
    "resource": "/c:/Users/thecodeadd/Documents/Stuff/Program/Programs/Python/Trialxlrd.py",
    "owner": "_generated_diagnostic_collection_name_#0",
    "code": {
        "value": "reportMissingImports",
        "target": {
            "$mid": 1,
            "external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
            "path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
            "scheme": "https",
            "authority": "github.com",
            "fragment": "diagnostic-severity-rules"
        }
    },
    "severity": 4,
    "message": "Import \"xlrd\" could not be resolved",
    "source": "Pylance",
    "startLineNumber": 1,
    "startColumn": 8,
    "endLineNumber": 1,
    "endColumn": 12

}]

对于 xlrd python 模块,您需要 2 个库。

  1. pip 安装 jinja2
  2. pip 安装 xlrd

这应该可以解决您的问题