Finds and runs debugpy for VS Code "remote attach" command line debugging.
debugger in VS
Code is superb. However debugging a
command line program which takes arguments is a little awkward to
invoke. The official
require you to edit the command line arguments in your
configuration which is cumbersome to do when you want to change
arguments for each run, particularly because the arguments have to be
quoted within a JSON data
This question on
describes the problem, but there is no adequate solution. This utility
provides a solution, follow the procedure to use
If you have the VS Code Python
installed then the full
debugpy debugger is already
bundled with it. You open a terminal window and run this utility to
invoke your program with arguments. The utility finds the path where
debugpy is installed and then
runs it for the program and arguments you specify, in listen mode.
Connect to it from within VS Code
using the Python "Remote Attach" debug configuration (using the default
host and port settings). You can
control+c and then re-run the command
with changed arguments using your shell history and command line editing
facilities, for each debug run. You can also run
debugpy explicitly installed for this case, to debug from VS Code
to a remote machine over a network.
This utility was developed on Arch Linux but should work on all Linux systems where VS Code is installed with the Python extension. The latest version and documentation is available at https://github.com/bulletmark/debugpy-run.
Arch users can install debugpy-run from the AUR.
Python 3.6 or later is required. Note debugpy-run is on
PyPI so just ensure that
python3-wheel are installed then type the following
to install (or upgrade):
$ sudo pip3 install -U debugpy-run
Or, to install from this source repository:
$ git clone http://github.com/bulletmark/debugpy-run $ cd debugpy-run $ sudo pip3 install -U .
Procedure to Use
Open VS Code for the directory where your command line program is located.
Ensure you have added a Debugging Configuration in your
launch.json. Specify "Remote Attach" and just accept the default arguments (i.e. host =
localhost, port =
5678). You only have to do this once for each project.
Open a terminal (either within VS Code, or external) and type:
$ debugpy-run my-program --myargs
debugpy-runwill start the
debugpydebugger for your program, output a message, and then wait to be connected by VS Code.
In VS Code, start debugging, e.g. set a breakpoint then start the Remote Attach debug session.
At any point you can
control+cthe terminal command and restart it with new command line arguments (e.g. using the convenience of your shell history and editing commands) and then restart the debug session in VS Code.
Remote Debugging On Another Host
debugpy-run utility first looks to find the
debugpy package in
~/.vscode/extensions directory. If it fails to find that
debugpy-run next tries to import
debugpy globally. This is is
done so you can install both
debugpy on a remote
headless server (e.g. where VS Code is not installed) and then debug a
program on that server from VS Code on your laptop/PC remotely over the
So for example, I may have a program which runs on a server which want to debug from VS Code on my laptop. I first make sure I install the necessary software on the server (you can also do this in the programs virtual environment of course):
$ sudo pip3 install -U debugpy $ sudo pip3 install -U debugpy-run
The start my program on the server using the debugger:
$ debugpy-run -p :5678 my-program --myargs
NOTE: We need to explicitly specify the
:port for this case so that
the port is opened on the external network interface so we can connect
to it from another machine. By default,
otherwise only accept local connections.
Then I go back to my laptop, ensure I have set up "Remote Attach"
debugging configured with host =
my-server and port =
5678, then start
Of course, you could start
debugpy directly yourself on the server but
debugpy-run wrapper is more convenient to use and makes the usage
consistent with the familiar way you start
debugpy-run on your
usage: debugpy-run [-h] [--listen] [-W] [-C] [-p PORT] [-g] [-r] [--log-to PATH | --log-to-stderr] [-m MODULE | -c CODE | --pid PID | -V] [program] ... Finds the "debugpy" package within your VSCode Python extension and then runs it for "remote attach" debugging of the program/module you specify. If not found in extensions then tries to run the globally installed "debugpy". positional arguments: program python program to execute and debug args remaining arguments to debug options: -h, --help show this help message and exit --listen listen on given port, default=True -W, --no-wait do not wait on listen for client, start immediately -C, --connect connect to given port rather than listen -p PORT, --port PORT [host:]port to use, default=5678 -g, --global-only only run the globally installed debugpy -r, --run-on-error re-run program/module even on error --log-to PATH log to given path --log-to-stderr log to stderr -m MODULE, --module MODULE python module to execute and debug -c CODE, --code CODE python code to execute and debug --pid PID python pid to attach and debug -V, --version output debugpy path and version
Copyright (C) 2021 Mark Blakeney. This program is distributed under the terms of the GNU General Public License. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.gnu.org/licenses/ for more details.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for debugpy_run-1.4-py3-none-any.whl