0

I'm trying to debug my python code with VS Code. Below is launch.json file.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "python": "/home/usr_name/anaconda3/envs/ENV_NAME/bin/python",
        }
    ]
}

It works fine until it finds break point. As soon as it reaches breakpoint, it stops debugging with below message (last few lines).

Backend TkAgg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
  File "/home/usr_name/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py", line 988, in trace_dispatch
    self.do_wait_suspend(thread, frame, event, arg)
  File "/home/usr_name/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_frame.py", line 165, in do_wait_suspend
    self._args[0].do_wait_suspend(*args, **kwargs)
  File "/home/usr_name/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2070, in do_wait_suspend
    keep_suspended = self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
  File "/home/usr_name/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 2093, in _do_wait_suspend
    self._activate_gui_if_needed()
  File "/home/usr_name/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd.py", line 1592, in _activate_gui_if_needed
    activate_function()
  File "/home/usr_name/.vscode/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/pydev_ipython/matplotlibtools.py", line 138, in activate_pylab
    pylab.show._needmain = False
AttributeError: module 'pylab' has no attribute 'show'

But in my conda environment, pylab.show works totally fine.

I already set Interpreter to conda env but that seems not directing VS code to use it in debug. Somehow it's stick with /home/usr_name/.vscode/extensions/ms-python. How to make it debug with python conda environment?

Edit: I'm not using matplotlib or pylab in my code. It works okay even with debugging. The problem occurs only when it hits breakpoint.

Brian Cho
  • 37
  • 11
  • From my side, the "show" comes from [matplotlib.pyplot](https://i.stack.imgur.com/CBX7K.png), what about directly using the "import matplotlib.pyplot as plt" to import, will the same issue still appears? – Bowman Zhu-MSFT Aug 10 '23 at 08:28
  • And for the environment configuration, please also try the settings.json file. Configure this: { "python.pythonPath": "/home/usr_name/anaconda3/envs/ENV_NAME/bin/python" } You can take a look of this: https://stackoverflow.com/questions/53653083/how-to-correctly-set-pythonpath-for-visual-studio-code – Bowman Zhu-MSFT Aug 10 '23 at 08:32
  • 1
    I updated the question. I'm not using matplolib and the problem happens whenever it hits breakpoint :( I tried to set python.pythonPath in settings.json but it says python.pythonPath is "Unknown Configuration Setting". – Brian Cho Aug 10 '23 at 08:48
  • please also share a minimal sample code if possible. – Bowman Zhu-MSFT Aug 10 '23 at 09:40
  • 1
    I'm running code from https://github.com/microsoft/muzic/blob/main/getmusic/track_generation.py I just wanted to see how things are working internally so I tried to debug it with VS code. Everything is fine until it hits the breakpoint.. – Brian Cho Aug 11 '23 at 01:25
  • Hi, I checked the source code you share, but there even no pylab be used, which line you set the breakpoint? – Bowman Zhu-MSFT Aug 11 '23 at 01:48
  • Right! That's exactly my point. I set breakpoint at line 260 trying to see how MIDI is encoded line by line. – Brian Cho Aug 11 '23 at 02:30

0 Answers0