相关疑难解决方法(0)

在 Ubuntu 20.04 LTS 上使用 Python 3.x 在 VS Code 中无法解析“导入“Path.to.own.script”Pylance (reportMissingImports)”

这是一个类似的情况我已经遇到过了几个月前使用pylint的事先pylance:

我的python 3.9x- 脚本(使用VS Codeon Ubuntu 20.04 LTS)从以下自定义“工具”导入开始:

import sys
sys.path.append(
    '/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/'
)

import General.Misc.general_tools as tools
Run Code Online (Sandbox Code Playgroud)

现在,Pylance声明:

Import "General.Misc.general_tools" could not be resolvedPylance (reportMissingImports)
Run Code Online (Sandbox Code Playgroud)

即使在程序执行期间模块被完美地导入,也会发生这种情况。

因此,为了确保Pylance理解这是一个现有的模块路径,除了sys.path.append(..)- 方法之外,我在settings.json- 文件中添加了以下内容:

{
    ...
    // Possible values: "Jedi", "Pylance", "Microsoft", "None".
    "python.languageServer": "Pylance",
    // NOTE on changing from microsoft to pylance language server: python.autoComplete.extraPaths --> python.analysis.extraPaths
    // Docs: https://github.com/microsoft/pylance-release/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings
    "python.analysis.extraPaths": [
        "/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts"
    ],
    ... …
Run Code Online (Sandbox Code Playgroud)

python-import python-3.x visual-studio-code vscode-settings pylance

32
推荐指数
3
解决办法
2万
查看次数