Debugging PyXLL with Visual Studio and PTVS

You can use Visual Studio 2015 and PTVS 2.2.6 to debug a PyXLL session.

As a starting point, you should have a working PyXLL environment, and some PyXLL User Defined Functions which are exposed to Excel via xl_func.

1. Make sure that Visual Studio (via PTVS) has access to the Python environment that runs your PyXLL code. 

2. In that same Python environment, install ptvsd (Python Tools for Visual Studio remote Debugging server):
pip install ptvsd

3. From inside of Visual Studio, open the pyxll Python module that you want to debug.

4. Import the ptvs debugger in your code:

import ptvsd

5. Add breakpoints where needed in the code.

6. Attach the debugger by using the command Debug -> Attach to Process. This opens the "Attach to Process" dialog. From the "Transport" combo box select "Python remote debugging", insert the "Qualifier", for example tcp://my_secret@locahost:5678 (update the host, port or secret depending on your configuration; 5678 is the default port for remote debugging).

7. Trigger the breakpoint from Excel by calling PyXLL functions. Excel will freeze, and Visual Studio will start the live debugging.



Please do not enter support requests in article comments


Have more questions? Submit a request


Powered by Zendesk