Skip to content

Commit ef25a0b

Browse files
2 parents 0a9ca8d + b3c0408 commit ef25a0b

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Check out the [tutorials](docs/) to get started! The only prerequisites are Exce
2020

2121
ExcelPython is a lightweight, easily distributable library for interfacing Excel and Python. It enables easy access to Python scripts from Excel VBA, allowing you to substitute VBA with Python for complex automation tasks which would be facilitated by Python's extensive standard library while sparing you the complexities of Python COM programming.
2222

23+
Do you like ExcelPython and find it useful? If so please consider donating something to support its continued development and get your name on the donor list!
24+
25+
<a href='https://pledgie.com/campaigns/26772'><img alt='Click here to lend your support to: ExcelPython and make a donation at pledgie.com !' src='https://pledgie.com/campaigns/26772.png?skin_name=chrome' border='0' ></a>
26+
2327
### Help me!
2428

2529
Check out the [docs](docs/) folder for tutorials to help you get started and links to other resources. Failing that, try the [issues section](https://github.com/ericremoreynolds/excelpython/issues?q=) or the [discussion forum on SourceForge](https://sourceforge.net/p/excelpython/discussion/general/).

docs/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ If you encounter any issues in getting the add-in set up consult the [troublesho
2121

2222
**Learn how to analyse the problem when something goes wrong**
2323

24+
* [Debugging](tutorials/Debugging01.md)
2425
* [Troubleshooting](tutorials/Troubleshooting01.md)

docs/tutorials/Debugging01.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Debugging code with ExcelPython
2+
3+
ExcelPython does not have any special provision for debugging Python code because it is fully compatible with existing Python debugging tools. Here we will see how to set up a couple of the most widely-used ones, [Python Tools for Visual Studio](#debugging-with-python-tools-for-visual-studio) and [PyDev](#debugging-with-eclipse-and-pydev).
4+
5+
## Debugging with Python Tools for Visual Studio
6+
7+
On Windows it is possible to debug Python scripts in Microsoft Visual Studio using an add-in called [Python Tools for Visual Studio](http://pytools.codeplex.com/) (PTVS). To get set up (full instructions can be found on the PTVS website) you need to
8+
9+
1. Install a recent version of Visual Studio, either Express or a commercial license.
10+
2. Download and install the relevant distribution of the PTVS add-in
11+
3. Install the PTVS debug package into your Python distribution
12+
4. Prepare your Python script to enable debugging in Visual Studio.
13+
14+
Assuming you've done steps 1 and 2, step 3 can be achieved using [PIP](https://pypi.python.org/pypi/pip).
15+
16+
```
17+
C:\>pip install ptvsd
18+
Downloading/unpacking ptvsd
19+
Running setup.py (path:c:\docume~1\user\locals~1\temp\pip_build_user\ptvsd\setup.py) egg_info for package ptvsd
20+
21+
Installing collected packages: ptvsd
22+
Running setup.py install for ptvsd
23+
24+
Successfully installed ptvsd
25+
Cleaning up...
26+
```
27+
28+
Now you should be able to `import ptvsd` in your Python interpreter.
29+
30+
Let's see how to prepare a [basic script](./Addin01.md) for debugging with PTVS
31+
32+
```python
33+
# Book1.py
34+
from xlpython import *
35+
36+
# Add these two lines
37+
import ptvsd
38+
ptvsd.enable_attach(secret='cows')
39+
40+
@xlfunc
41+
def DoubleSum(x, y):
42+
return 2 * (x + y)
43+
```
44+
45+
These to lines enable us to attach the Visual Studio debugger to the Python script, so that we can debug it. Note that the Python process itself must be running for this to work, and ExcelPython does not launch it until it is needed - so just to make sure that it is running and that the `Book1.py` script is loaded, click 'Import Python UDFs'.
46+
47+
At this point you may need to unblock a port on the Windows firewall:
48+
49+
![image](https://cloud.githubusercontent.com/assets/5197585/4387988/f02fbbe8-43e4-11e4-997e-31f12adbdf98.png)
50+
51+
Having done this you should now be in a position to attach the Visual Studio debugger to the Python script. To do this:
52+
* open the Debug > Attach to Process dialog
53+
* select 'Python remote debugging' as the transport
54+
* specify the relevant qualifier in the 'Qualifier' box, for example `cows@localhost`
55+
* click refresh and select the Python process
56+
57+
![image](https://cloud.githubusercontent.com/assets/5197585/4388048/e5ae4c06-43e5-11e4-8b24-300aa0ab3d4e.png)
58+
59+
Now you can set breakpoints in the code and the next time your function is invoked from Excel, the execution will be interrupted when the breakpoint is hit.
60+
61+
![image](https://cloud.githubusercontent.com/assets/5197585/4388088/59fefbaa-43e6-11e4-945a-31d66d3e2730.png)
62+
63+
## Debugging with Eclipse and PyDev
64+
65+
Coming soon!

0 commit comments

Comments
 (0)