无法让VSCode / Python调试器找到我的项目模块 [英] Can't get VSCode/Python debugger to find my project modules
问题描述
我有一个项目,正在尝试调试 main.py
。我真的很困惑,为什么在运行调试器时从文件顶部的导入中得到以下错误(仅):
I have a project and am trying to debug my main.py
. I am really confused why I am getting the following error from the imports at the top of my file (only) when running the debugger:
Exception has occurred: ModuleNotFoundError
No module named 'bbb'
File "/Users/maxepstein/myproject/bbb/train/__main__.py", line 8, in <module>
from bbb.mysubfolder.myfile import myfunction
我的项目文件夹结构,如下所示打印语句(如调试器所示)确认我的'bbb'模块存在,并且具有__init __。py:
My project folder structure, as shown by these print statements (as shown by the debugger) confirms my 'bbb' module exists, and has an __init__.py:
import os
print(os.getcwd())
print(os.listdir())
print(os.listdir('bbb'))
/Users/maxepstein/myproject
['requirements.txt', 'bbb', 'resources', '__init__.py', 'readme.md', 'results', '.gitignore', '.git', '.vscode', 'bbenv']
['config', 'tests', '__init__.py', 'utils', 'predict', 'train']
我正在尝试调试为调试当前文件-集成终端,以下是我的debug settings.json中适用的调试设置。在网上搜索后,我真的以为在下面添加 cwd: / Users / maxepstein / myproject
,但这没有帮助。
I'm trying to debug as "debug current file - integrated terminal", below is the applicable debug settings from my debug settings.json. After searching online, I really thought adding "cwd": "/Users/maxepstein/myproject"
below would be my solution but it hasn't helped.
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "/Users/maxepstein/myproject"
}
推荐答案
在VS Code中调试Python模块时,我使用Module调试配置而不是Current File。对于您来说,它可能看起来像这样:
When I am debugging a Python module in VS Code I use the Module debug configuration instead of the Current File one. For you it might look like this:
{
"name" : "Python: Module",
"type" : "python",
"request": "launch",
"module": "bbb",
"args": []
}
请参见文档 https://code.visualstudio.com/docs/python/debugging
此外,在VS Code中,这些步骤将自动为您填充以下设置:
Also, in VS Code, these steps will auto-populate these settings for you:
调试->添加配置-> Python:模块
Debug -> Add Configuration -> Python: Module
这篇关于无法让VSCode / Python调试器找到我的项目模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!