vscode调试python项目_无法让VSCode / Python调试器找到我的项目模块

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

from bbb.mysubfolder.myfile import myfunction

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']

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"

}

解决方案

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": []

}

Also, in VS Code, these steps will auto-populate these settings for you:

Debug -> Add Configuration -> Python: Module

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值