Reputation: 83
I want to debug python udf code in pydev on same host as excel. I looked at the official doc but couldn't get the concept or get it working. As per document I have put these lines at the end of my udfs module:
if __name__ == '__main__':
xw.serve()
The doc also says:
Depending on which IDE you use, you might want to run things in “debug” mode (e.g. in case your using PyCharm or PyDev):
I don't understand what 'run things' mean above.
Also, as per pydev instructions for remote debugging, one has to use one of the below menu button(s) in Eclipse:
and add this code:
import pydevd
pydevd.settrace()
I am confused as to which all steps one needs to follow for remote debugging in pydev a udf call made from excel. Can anyone share steps of udf & pydev debugging?
Pydev is win 64-bit and excel is 2007 (32-bit).
Upvotes: 1
Views: 434
Reputation: 7070
With xlwings, you won't need any remote debugging or attaching to a running process, so no need to introduce any new code like settrace()
. In fact, the nice thing is that standard debugging works out of the box with xlwings and thus with any IDE.
You need to set UDF_DEBUG_SERVER = True
in the VBA settings. Then, when you recalculate the Excel spreadsheet, the formulas will give you an error.
This means that you now need to run the Python file that includes this at the end:
if __name__ == '__main__':
xw.serve()
These lines starts the COM server. In Eclipse, if you just hit Run > Run last launched
, it will work fine, i.e. you will see any output from your code (like print commands) in PyDev's Console when you recalculate the UDFs again.
However, to make the code stop at breakpoints, you need to select Run > Debug Last Launched
.
Upvotes: 1