[英]Cannot import local files in python debugger (vs code)
I am doing the following:我正在做以下事情:
mkdir folder_structure
mkdir folder_structure/utils
touch folder_structure/utils/tools.py
touch folder_structure/main.py
from folder_structure.utils.tools import dummy
if __name__ == '__main__':
dummy()
def dummy():
print("Dummy")
touch folder_structure/__init__.py
touch folder_structure/utils/__init__.py
Run the vs code debugger运行 vs 代码调试器
I'm getting:我越来越:
Exception has occurred: ModuleNotFoundError
No module named 'folder_structure'
File "/Users/davidmasip/Documents/Others/python-scripts/folder_structure/main.py", line 1, in <module>
from folder_structure.utils.tools import dummy
I have the following in my launch.json:我的 launch.json 中有以下内容:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
}
}
]
}
How can I import a local module when using the debugger?使用调试器时如何导入本地模块?
This works for me:这对我有用:
python -m folder_structure.main
You need replace你需要更换
from folder_structure.utils.tools import dummy
With和
from utils.tools import dummy
Changing the launch.json to this:将 launch.json 更改为此:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "folder_structure.main",
"justMyCode": true
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
},
"cwd": "${workspaceRoot}",
}
]
}
and debugging the module works.并调试模块工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.