【问题标题】:Pylance import could not be resolvedPylance 导入无法解决
【发布时间】:2021-09-13 02:09:59
【问题描述】:

我在主 python 文件的目录中有一个名为 helper 的模块,但是 pylance 警告 Import "helper" could not be resolved 即使 python3 完美运行它,如何解决这个问题?
helper 是一个目录

目录结构:

main.py
helper/
└── __init__.py

main.py:

import helper
helper.run()

【问题讨论】:

  • 您能否编辑您的问题以显示您如何导入helper 模块并显示您的代码目录结构?

标签: python-3.x visual-studio-code python-import pylance


【解决方案1】:

尝试添加

  "python.analysis.extraPaths": ["./helper"]

到您的 .vscode/settings.json 文件,如此处所述https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#unresolved-import-warnings

【讨论】:

  • 为我工作。也许您需要更详细地描述您的结构。即使您收到 Pylance 警告,代码是否仍然有效? “助手”是一个目录吗?您是否尝试过“从 helper.myfile 导入 myfunction”?
  • 更新帖子
【解决方案2】:

我不知道为什么,但是现在可以了,谢谢您的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    相关资源
    最近更新 更多