VS代码导入分辨率带有Pylance(ModulenotFoundError)

发布于 2025-01-24 22:46:31 字数 401 浏览 3 评论 0 原文

具有塔的导入分辨率错误,无法识别软件包。 (Windows 10)

  • 在本地目录上激活的VENV
  • 已确认的PIP清单,该软件包已正确安装了该软件包
  • 在管理员
  • 检查时已安装软件包,该软件包已安装在 /lib /site -packages文件夹中,用于我的python安装,

错误:

ModuleNotFoundError: No module named 'abc123'

收到 ,悬停在破碎的进口中说

“ packagefoo”无法访问

导入“ packagefoo”无法解析塔

Having an import resolution error with pylance not recognizing packages. (Windows 10)

  • Venv activated on the local directory
  • Confirmed pip -list that the package is correctly installed
  • Ran VS code as administrator
  • Checked the package is installed in the /Lib/site-packages folder for my python installation

Receiving the error:

ModuleNotFoundError: No module named 'abc123'

Inside the file, hovering over the broken import says

"packageFoo" is not accessible

Import "packageFoo" could not be resolved Pylance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最偏执的依靠 2025-01-31 22:46:31

我发现了许多类似的问题,但没有这个具体的答案。

在VSCODE中,在顶部工具栏上找到文件下拉列表。

选择首选项> 设置(ctrl +)

搜索栏中的

,搜索 pylance 滚动到python>分析:额外路径

“

单击'添加项目'按钮

下一步您需要确定Windows中Python的安装路径。在那条路径中,有一个“ lib”文件夹。在LIB文件夹下,有一个“站点包装”文件夹。这是所有PIP安装软件包的文件夹。

对我来说,它看起来像这样:

C:\Users\user_name_here\AppData\Local\Programs\Python\Python310\Lib\site-packages

复制此路径并将其添加为Pylance Vscode设置中的项目。

此外:您可以打开'Python>分析:索引下面的设置以编辑JSON文件。在这里,您可以复制并粘贴相同的路径,并带有额外的“反铲逃脱角色”。注意到第一个条目后有一个逗号,如果存在。

I found many similar questions, but not this specific answer.

In vscode, locate the file dropdown on the top toolbar.

Select preferences > Settings (Ctrl +)

In the search bar, search for pylance

Scroll down to Python > Analysis: Extra Paths

vscode pylance settings

Click 'add item' button

Next step you need to identify the installation path for python in windows. In that path there is a 'Lib' folder. Under lib folder there is a 'site-packages' folder. This is the folder for all your pip installed packages.

For me it looked like this:

C:\Users\user_name_here\AppData\Local\Programs\Python\Python310\Lib\site-packages

Copy this path and add it as the item in the pylance vscode settings.

Additionally: You can open the 'Python > Analysis: Indexing' settings below to edit a JSON file. Here you copy and paste the same path, with extra '' - backspace escape characters. Noting there is a comma after the first entry, if it exists.

很快妥协 2025-01-31 22:46:31

如果您已正确安装 Pylance 当您打开 .py 文件时,则将激活此扩展名。现在检查 settings.json 文件,并添加以下句子:
“ python.languageserver”:“默认值”或“ pylance”

 可能是因为 Pylance 不是指向是您的已安装或另一个软件包,并且该错误是始发的( modulenotfounderror:no模块名为“ ABC123'>),那么您可能需要在 settings.json.json 此配置中验证:

python.Alysis.AutoSearchPaths true

python.Analysis.StubPath ./ trips> ./ typings

python.analysision.extrapaths在

​:<代码> true

If you have correctly installed Pylance when you open a .py file, this extension would be activate. Now check settings.json file and add the following sentence:
"python.languageServer": "Default" or "Pylance".

 It is probably that your problem is caused because Pylance is not pointed to the path where is your library installed or another package and the error is originated (ModuleNotFoundError: No module named 'abc123'), then you may need to verify in your settings.json this configuration:

python.analysis.autoSearchPaths : true

python.analysis.stubPath:./typings

python.analysis.extraPaths:["./folder"] (if your project use a specific folder)

python.analysis.autoImportCompletions:true

倾`听者〃 2025-01-31 22:46:31

确保模块上有一个.py扩展。

Make sure there is a .py extension on the module.

維他命╮ 2025-01-31 22:46:31

尝试以下操作:

  1. 首选项&GT;设置&gt;搜索 Pylance
  2. 查找 Python&gt;分析:诊断严重程度替代
  3. 单击在settings.json
  4. 添加以下以下内容“ python.analysis.diarosticseverityoverrides”:{} 的curly brackets { }
        "reportGeneralTypeIssues": "none",
        "reportOptionalMemberAccess": "none",
        "reportOptionalSubscript": "none",

这应该解决一些不间断的下划线。还有其他选择要考虑:

  • “ reportMissingimports” :控制与导入分辨率相关的诊断的严重性。
  • “ ReportMissingModulesource” :控制缺少导入模块的源文件的诊断严重程度。
  • “ ReportOptionalCall” :在调用可能为 none 的东西时控制诊断的严重性。
  • “ ReportOptionalable” :在迭代可能 none 上时,控制诊断的严重性。
  • “ ReportOptionalContextManager” :使用可能 none 作为上下文管理器时,控制诊断的严重性。
  • “ ReportOptionalOperand” :控制可能是 none 的操作时诊断的严重性。
  • “ reportuntypedbaseclass” :在基类无型时控制诊断的严重性。
  • “ reportuntypednamedtuple” :当指定元组没有类型时,控制诊断的严重性。
  • “ ReportPrivateUsage” :访问私人成员时控制诊断的严重性(即,从下划线开始)。
  • “ ReportConstantredefinition” :当在本地范围重新定义常数时,控制诊断的严重性。

这些选项中的每一个都可以设置为“错误” “警告” “信息” “ none” 取决于您的喜好。

Try this:

  1. Preferences > Settings > Search pylance
  2. Find Python> Analysis: Diagnostic Severity Overrides
  3. Click Edit in settings.json
  4. Add following in "python.analysis.diagnosticSeverityOverrides": { }'s curly brackets { }
        "reportGeneralTypeIssues": "none",
        "reportOptionalMemberAccess": "none",
        "reportOptionalSubscript": "none",

This should solve some un-intended underlines. There are other options to consider:

  • "reportMissingImports": Controls the severity of diagnostics related to import resolution.
  • "reportMissingModuleSource": Controls the severity of diagnostics for missing source files of imported modules.
  • "reportOptionalCall": Controls the severity of diagnostics when calling something that might be None.
  • "reportOptionalIterable": Controls the severity of diagnostics when iterating on something that might be None.
  • "reportOptionalContextManager": Controls the severity of diagnostics when using something that might be None as a context manager.
  • "reportOptionalOperand": Controls the severity of diagnostics when operating on something that might be None.
  • "reportUntypedBaseClass": Controls the severity of diagnostics when a base class is untyped.
  • "reportUntypedNamedTuple": Controls the severity of diagnostics when a named tuple does not have types.
  • "reportPrivateUsage": Controls the severity of diagnostics when accessing a private member (i.e., begins with an underscore).
  • "reportConstantRedefinition": Controls the severity of diagnostics when a constant is redefined in a local scope.

Each of these options can be set to "error", "warning", "information", or "none" depending on your preference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文