VS代码导入分辨率带有Pylance(ModulenotFoundError)
具有塔的导入分辨率错误,无法识别软件包。 (Windows 10)
- 在本地目录上激活的VENV
- 已确认的PIP清单,该软件包已正确安装了该软件包
- 在管理员
- 检查时已安装软件包,该软件包已安装在 /lib /site -packages文件夹中,用于我的python安装,
错误:
ModuleNotFoundError: No module named 'abc123'
收到 ,悬停在破碎的进口中说
“ packagefoo”无法访问
导入“ packagefoo”无法解析塔
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现了许多类似的问题,但没有这个具体的答案。
在VSCODE中,在顶部工具栏上找到文件下拉列表。
选择首选项> 设置(ctrl +)
搜索栏中的
,搜索 pylance 滚动到python>分析:额外路径
单击'添加项目'按钮
下一步您需要确定Windows中Python的安装路径。在那条路径中,有一个“ lib”文件夹。在LIB文件夹下,有一个“站点包装”文件夹。这是所有PIP安装软件包的文件夹。
对我来说,它看起来像这样:
复制此路径并将其添加为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
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:
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.
如果您已正确安装
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 checksettings.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 yoursettings.json
this configuration:python.analysis.autoSearchPaths
:true
python.analysis.stubPath
:./typings
python.analysis.extraPaths
:["./folder"]
(if your project use a specificfolder
)python.analysis.autoImportCompletions
:true
确保模块上有一个.py扩展。
Make sure there is a .py extension on the module.
尝试以下操作:
Pylance
Python&gt;分析:诊断严重程度替代
在settings.json
中“ python.analysis.diarosticseverityoverrides”:{}
的curly brackets{ }
这应该解决一些不间断的下划线。还有其他选择要考虑:
“ reportMissingimports”
:控制与导入分辨率相关的诊断的严重性。“ ReportMissingModulesource”
:控制缺少导入模块的源文件的诊断严重程度。“ ReportOptionalCall”
:在调用可能为none
的东西时控制诊断的严重性。“ ReportOptionalable”
:在迭代可能none
上时,控制诊断的严重性。“ ReportOptionalContextManager”
:使用可能none
作为上下文管理器时,控制诊断的严重性。“ ReportOptionalOperand”
:控制可能是none
的操作时诊断的严重性。“ reportuntypedbaseclass”
:在基类无型时控制诊断的严重性。“ reportuntypednamedtuple”
:当指定元组没有类型时,控制诊断的严重性。“ ReportPrivateUsage”
:访问私人成员时控制诊断的严重性(即,从下划线开始)。“ ReportConstantredefinition”
:当在本地范围重新定义常数时,控制诊断的严重性。这些选项中的每一个都可以设置为
“错误”
,“警告”
,“信息”
或“ none” 取决于您的喜好。
Try this:
pylance
Python> Analysis: Diagnostic Severity Overrides
Edit in settings.json
"python.analysis.diagnosticSeverityOverrides": { }
's curly brackets{ }
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 beNone
."reportOptionalIterable"
: Controls the severity of diagnostics when iterating on something that might beNone
."reportOptionalContextManager"
: Controls the severity of diagnostics when using something that might beNone
as a context manager."reportOptionalOperand"
: Controls the severity of diagnostics when operating on something that might beNone
."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.