如何使用 python 脚本解决 VSCode 导入警告? [英] How to resolve VSCode import warnings with python scripts?
本文介绍了如何使用 python 脚本解决 VSCode 导入警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
VSCode 会在我从同一目录导入 python 文件时发出 warning
,但实际上当脚本运行时一切正常.
VSCode gives a warning
whenever I import a python file from the same directory, but in practice everything works fine when the scripts run.
在示例目录中:
root_folder
+-- __init__.py (empty)
+-- __main__.py (empty)
+-- __import.py (contains Parent class)
+-- toImport.py (contains Child(Parent) class)
我在 toImport.py
中尝试以下操作:
I try the following in toImport.py
:
from __import import Parent
class Child(Parent): ...
尽管我一直收到 warning: unresolved import
即使它有效.我该如何解决这个问题,还是 VSCode 问题?
Although I keep getting a warning: unresolved import
even if it works. How can I resolve this issue or is it a VSCode issue?
推荐答案
将此添加到您的项目 .vscode/settings.json
文件中.
Add this to your projects .vscode/settings.json
file.
{
"python.autoComplete.extraPaths": ["./root_folder"]
}
这篇关于如何使用 python 脚本解决 VSCode 导入警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文