When you stop debugging, Visual Studio detaches from the program, which continues to run on the remote computer. After you do so, Visual Studio on your local computer stops at that breakpoint, shows local variables, and so on: For example, set a breakpoint on the if guess < number: line, then switch over to the remote computer and enter another guess. Visual Studio then switches into debugging mode while the script continues to run on the remote computer, providing all the usual debugging capabilities. Select the process to debug and then Attach, or double-click the process. If you happen to start another program on the remote computer after populating this list, select the Refresh button.
Press Enter to populate the list of available debugpy processes on that computer: In the Connection Target field, enter tcp://:5678 where is that of the remote computer (which can be either an explicit address or a name like ), and :5678 is the remote debugging port number. In the Attach to Process dialog that appears, set Connection Type to Python remote (debugpy).
(Optional) To have IntelliSense for debugpy on your local computer, install the debugpy package into your Python environment. It doesn't matter where the file is located, but its name should match the name of the script on the remote computer. In these steps, we set a simple breakpoint to stop the remote process.Ĭreate a copy of the remote file on the local computer and open it in Visual Studio. There is also an is_client_connected function that returns True if the debugger is attached (note that there is no need to check this result before calling any other debugpy functions). In addition to listen and wait_for_client, debugpy also provides a helper function breakpoint, which serves as a programmatic breakpoint if the debugger is attached. Install the debugpy package into your environment using pip3 install debugpy. Name = input('Hello! What is your name?\n')
On the remote computer, create a Python file called guessing-game.py with the following code: import random
Ubuntu for the VM is convenient because Python is installed by default otherwise, see the list on Install a Python interpreter of your choice for additional Python download locations.įor details on creating a firewall rule for an Azure VM, see Open ports to a VM in Azure using the Azure portal. You can easily create a Linux virtual machine on Azure and access it using Remote Desktop from Windows. Port 5678 (inbound) opened on that computer's firewall, which is the default for remote debugging.
This hosting requires a small modification to your code to import and enable the server, and may require network or firewall configurations on the remote computer to allow TCP connections.įor an introduction to remote debugging, see Deep Dive: Cross-platform remote debugging (, 6m22s), which is applicable to both Visual Studio 20. When using ptvsd, the Python code being debugged hosts the debug server to which Visual Studio can attach. It can also debug remotely on a different operating system, device, or Python implementation other than CPython using the ptvsd library. Visual Studio can launch and debug Python applications locally and remotely on a Windows computer (see Remote debugging).