I'm going to show how you can debug yours Stealth scripts written in Python using Pydev.
If you have any question or something is not clear please let me know, but in english (I don't speak russian!).
Prerequisites
- Any PC able to run the Eclipse IDE (this is the platform on the top of witch we'll run our debugger);
- The Python environment compatible with Stealth (for this tutorial I've used 2.7.x). If you're reading this probably you know what I'm speaking of ;
- Pydev extension for Eclipse (this is where the sweet part of debug takes place ).
Installing Eclipse
Download a version of Eclipse that suits your PC and install it (for this tutorial I've used the Eclipse IDE for Java EE Developers).
Installing PyDev on top of Eclipse
- From Eclipse menu choose Help -> Install New Software...
View Screen Capture - Click on the "Add" button to add a the PyDev site;
View Screen Capture - In the new prompt that appears type the name you like (I used "PyDev") and as site use the official site for PyDev releases: http://pydev.org/updates
View Screen Capture - Now you are ready to install PyDev. You don't need Mylyn itegration (see the screen below).
View Screen Capture
Add the Python interpreter
- From the menu choose Window -> Preferences
View Screen Capture - Expand the PyDev tree (step 1), choose "Interpreter Python" (step 2), click on the "New" Button (step 3) and point Eclipse to your python.exe path (on my machine as you can see is "D:\Python27\python.exe", the screen has been taken after configuring so you see the result of it).
View Screen Capture
- On the top right corner click on the Open perspective button and select Other
View Screen Capture - Select PyDev and confirm
View Screen Capture
- Be sure to be in PyDev perspective and click on a empty spot on you toolbar and from the menu choose "Customize Perspective...";
View Screen Capture - In the "Commands Group Availability" tab put the check on the PyDev Debug option;
View Screen Capture - Now you should see the remote debugging buttons in you toolbar:
View Screen Capture - Click on the green one and start the remote debugger (you can be sure that the debugger is started checking at the bottom of Eclipse interface in the Console log).
View Screen Capture
Now that everything is set up in PyDev we need to address Stealth to interact with it.
Referencing the pysrc module inside Stealth installation
- The first thing to make here is to find where the original pysrc module (bundled inside PyDev) has bee installed on our machine. The path changes depending on the installation. Typically it is in a sub folder of the Eclipse installation; in my machine it was ...\eclipse\plugins\org.python.pydev.debug_2.3.0.2011121518\pysrc on your machine should be something very similar.
- Once you've found it make a copy of the whole pysrc folder and place it wherever you like it. On my machine i putted it in the following path "D:\stealth\script\pydebug\pysrc" being "D:\stealth\" the path where my Stealth installation resides;
- Now go inside the newly created directory ("D:\stealth\script\pydebug\pysrc") and create a new empty file and name it "__init__.py".
Now everything is ready and you only need to make your script aware of the remote debugger. To make this happen add this snippet in the header of your Python script (I'm going to comment it line by line later on) before launching it from Stealth (not PyDev!):
Code: Select all
REMOTE_DBG = True
if REMOTE_DBG:
sys.path.append('D:\\stealth\\script\\pydebug')
print str(sys.path)
import pysrc.pydevd as pydevd
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True)
Code: Select all
REMOTE_DBG = True
Code: Select all
sys.path.append('D:\\stealth\\script\\pydebug')
Code: Select all
import pysrc.pydevd as pydevd
Code: Select all
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True)
Known Issues
PyDev, will only promt you one time asking where to look for debug source and then will save the location and use it for following debug sessions. This is good if you are debugging the same script, but if you want to debug another script you'll have to make the following steps:
- From the menu choose Window -> Preferences
View Screen Capture - Expand the PyDev tree and choose Debug -> Source Locator; select the last reference you used and remove it.
View Screen Capture
References
This guide has been inspired from the following pages:
- PyDev Install Guide;
- XBMC guide on how to remote debug Python scripts.
Thank to Alex that in this post gave me the initial tips on how to start.