我正在执行以下操作:
1.第一个月
mkdir folder_structure/utils
touch folder_structure/utils/tools.py
touch folder_structure/main.py
- Write in main.py:
from folder_structure.utils.tools import dummy
if __name__ == '__main__':
dummy()
- Write in tools.py:
def dummy():
print("Dummy")
touch folder_structure/__init__.py
touch folder_structure/utils/__init__.py
1.运行vs代码调试器
我得到:
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
我的launch.json中包含以下内容:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceRoot}"
}
}
]
}
使用调试器时如何导入本地模块?
这对我很有效:
python -m folder_structure.main
2条答案
按热度按时间1zmg4dgp1#
你需要替换
与
zc0qhyus2#
将launch.json更改为:
调试模块工作。