Difference between revisions of "Python Debugging"

From Vectorworks Developer
Jump to: navigation, search
(make clearer)
(Invert the sequence, more clear for the unexperienced user)
Line 6: Line 6:
 
== Debugging with Aptana Studio ==
 
== Debugging with Aptana Studio ==
  
I have experimented with Aptana Studio (http://www.aptana.com/products/studio3/download.html) which is a version of http://en.wikipedia.org/wiki/Eclipse_(software)
+
I have experimented with [http://www.aptana.com Aptana Studio] which is a version of [http://en.wikipedia.org/wiki/Eclipse_(software) Eclipse].
  
Aptana is an IDE that allows you to manage Python projects and can debug remote python engines like Vectorworks. It includes PyDev (http://pydev.org/) for that which, by itself, is a plug-in to do python in Eclipse.
+
Aptana is an IDE that allows you to manage Python projects and can debug remote python engines like Vectorworks. It includes [http://pydev.org/ PyDev] for that which, by itself, is a plug-in to do python in Eclipse.
  
 
Anyway, you can remote debug, and here is how:
 
Anyway, you can remote debug, and here is how:
 
http://pydev.org/manual_adv_remote_debugger.html
 
http://pydev.org/manual_adv_remote_debugger.html
  
Here is the setup procedure:
+
== Setup Aptana ==
# Install Python 3.3 runtime (http://www.python.org/download/) I’ll hook Aptana to this version later. This is technically not necessary, but I prefer to have it so Aptana could report syntax errors while editing.
+
# Install Aptana Studio 3 (http://www.aptana.com/products/studio3/download.html)
+
# Run Aptana and specify a workspace directory outside Vectorworks path. This is VERY important for the reason that workspace directory will contain a ton of files that start with ‘.’. If this path is visible by Vectorworks, it will make it launch very slowly (from traversing all these files and sub-folders)
+
# Now, you can create a project. File -> New -> Project... > General
+
# Only the first time, this process would require to setup Python engine. Now, let the software find the python and set it up automatically: Preferences > PyDev > Interpreters > Python Interpreter, click on "Advanced Auto-Config" and select the Python 3.3 you just installed in step 1. We wont actually use it, but will let Aptana use it to syntax check.
+
  
The way the debug works is to use the remote debugger of Aptana: http://pydev.org/manual_adv_remote_debugger.html
+
# Install Python 3.3 runtime ([http://www.python.org/download/ download]) I’ll hook Aptana to this version later. This is technically not necessary, but I prefer to have it so Aptana could report syntax errors while editing.
 +
# Install Aptana Studio 3 ([http://www.aptana.com/products/studio3/download.html download]).
 +
# Aptana supports many languages. Only the first time, you must setup the Python interpreter (the above mentioned [http://en.wikipedia.org/wiki/PyDev pydev] plug-in):
 +
#:* '''Preferences > PyDev > Interpreters > Python Interpreter'''
 +
#:* click on '''Advanced Auto-Config'''
 +
#:* select the Python 3.3 you just installed in step 1. We wont actually use it, but will let Aptana use it to syntax check.
 +
#:: See [http://pydev.org/manual_101_interpreter.html Configure Interpreter] in the pdev documentation for more infos.
 +
# Specify a ''Workspace'': the directory where you store your ''Projects'', in our case the plug-in folders with the code. Depending on Aptana's defaults, the application will prompt you with a workspace choice at every launch:
 +
#:* When prompted at start: choose a directory outside any Vectorworks path.
 +
#:* When you need to manually change the path: '''File > Switch Workspace > Other...''': choose a directory outside any Vectorworks path.
 +
#:: Mac Example: <User>/Documents/Python_VW
 +
#:: This is VERY important for the reason that a workspace directory will contain a ton of files that start with ‘.’. If this path is visible by Vectorworks, it will make it launch very slowly (from traversing all these files and sub-folders). Also take care to select a directory with proper read/write user rights, for example within the folder "Documents".
 +
#:: Note: you can have multiple workspaces. The list will be visible here: '''Preferences > General > Startup and Shutdown > Workspaces'''
 +
# Now, you can create or import a ''Project'': a directory containing all files needed for a plug-in, for example the folder [[Python Sample Menu Command]].
 +
#:* Import an existing ''Project'' (for example the [[Python Sample Menu Command]]): '''File -> New -> Project... > General'''
 +
#:* Create a new python ''Project'': '''file > new > project > PyDev > PyDev project'''
 +
#:: See [http://pydev.org/manual_101_project_conf.html Creating a Project] in the pdev documentation for more infos.
  
First, you must include an import to the PyDev remote debugger in your script. The [[Python Sample Menu Command]] contains commented code that enables PyDev debugger.
+
== Set up VW to debug using Aptana  ==
  
 +
The way the debug works is to use the remote debugger of Aptana: http://pydev.org/manual_adv_remote_debugger.html.  Set up in Vectorworks the correct Python environment path:
 +
#: Vectorworks menu '''Tools -> Plug-ins -> Script Options''' : add an environment path to the needed Folder location:
 +
#:* Win example: D:\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013012902\pysrc
 +
#:* Mac example: /Applications/Aptana Studio 3/plugins/org.python.pydev_3.0.0.1388187472/pysrc
 +
#:; Note: You may need to change that to the place where you have installed the Aptana Studio application.
 +
#: [[Image:PythonAptanaPyDevPathSetup.jpg]]
 +
# Include an import to the PyDev remote debugger in your script. The [[Python Sample Menu Command]] contains commented code that enables PyDev debugger:
 
<code lang="py">
 
<code lang="py">
 
import pydevd
 
import pydevd
Line 29: Line 47:
 
</code>
 
</code>
  
Then your script will fail because the 'pydevd' module is not found.
+
; Warning: if your script fails it can be because the 'pydevd' module is not found. To fix that you must point Vectorworks' Python to the correct environment path to find the missing module.
  
To fix that you must point Vectorworks' Python to the correct environment path to find the missing module.
+
== Enable the remote debugger in Aptana ==
  
Go to the Vectorworks menu Tools -> Plug-ins -> Script Options and add an environment path to the needed Folder location:
+
Then you go to Aptana Studio and enable the remote debugger (instructions under http://pydev.org/manual_adv_remote_debugger.html) and run your script in Vectorworks. You may need to enable the Debug perspective in Aptana before being able to enable the debug server, or the mentioned "green button" of the instructions will not be available:  
* Win example: D:\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013012902\pysrc
+
# How to enable the Debug Perspective view:  
* Mac example: /Applications/Aptana Studio 3/plugins/org.python.pydev_3.0.0.1388187472/pysrc
+
#* '''Window > Open Perspective > Other > Debug''': a new icon with a green bug will appear on the rightmost corner of the window (see screenshot below), this toggles the debug perspective
 
+
#* while in the Debug Perspective view, start the remote pydev debugger server: click on the green button with the bug and a P, which you'll find about the middle of the window (again screenshot below)
; Note: You may need to change that to the place where you have installed the Aptana Studio application.
+
#: [[Image:PythonAptanaPyDevDebugServerSetup.jpg]]
 
+
[[Image:PythonAptanaPyDevPathSetup.jpg]]
+
 
+
 
+
 
+
Then you go to Aptana Studio and enable the remote debugger (http://pydev.org/manual_adv_remote_debugger.html) and run your script in Vectorworks.
+
 
+
; Note: You may need to enable the Debug perspective in Aptana before being able to enable the debug server, or the mentioned "green button" will not be available:  
+
# enable the Debug Perspective view: Window > Open Perspective > Other > Debug: a new icon with a green bug will appear on the rightmost corner of the window (see screenshot below), this toggles the debug perspective
+
# while in the Debug Perspective view, start the remote pydev debugger server: click on the green button with the bug and a P, which you'll find about the middle of the window (again screenshot below)
+
[[Image:PythonAptanaPyDevDebugServerSetup.jpg]]
+
  
 
== See Also ==
 
== See Also ==
  
 
Python basic information: [[Python]]
 
Python basic information: [[Python]]

Revision as of 03:26, 13 May 2015

Python is open source scripting engine and there are many free and paid IDEs that can hook into the engine and debug. I guess you can search and experiment with what is out there in the internet. Maybe you can find an easier way to make it work.

.Python|Python ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix ..Python Debugging|Debugging with Python

Debugging with Aptana Studio

I have experimented with Aptana Studio which is a version of Eclipse.

Aptana is an IDE that allows you to manage Python projects and can debug remote python engines like Vectorworks. It includes PyDev for that which, by itself, is a plug-in to do python in Eclipse.

Anyway, you can remote debug, and here is how: http://pydev.org/manual_adv_remote_debugger.html

Setup Aptana

  1. Install Python 3.3 runtime (download) I’ll hook Aptana to this version later. This is technically not necessary, but I prefer to have it so Aptana could report syntax errors while editing.
  2. Install Aptana Studio 3 (download).
  3. Aptana supports many languages. Only the first time, you must setup the Python interpreter (the above mentioned pydev plug-in):
    • Preferences > PyDev > Interpreters > Python Interpreter
    • click on Advanced Auto-Config
    • select the Python 3.3 you just installed in step 1. We wont actually use it, but will let Aptana use it to syntax check.
    See Configure Interpreter in the pdev documentation for more infos.
  4. Specify a Workspace: the directory where you store your Projects, in our case the plug-in folders with the code. Depending on Aptana's defaults, the application will prompt you with a workspace choice at every launch:
    • When prompted at start: choose a directory outside any Vectorworks path.
    • When you need to manually change the path: File > Switch Workspace > Other...: choose a directory outside any Vectorworks path.
    Mac Example: <User>/Documents/Python_VW
    This is VERY important for the reason that a workspace directory will contain a ton of files that start with ‘.’. If this path is visible by Vectorworks, it will make it launch very slowly (from traversing all these files and sub-folders). Also take care to select a directory with proper read/write user rights, for example within the folder "Documents".
    Note: you can have multiple workspaces. The list will be visible here: Preferences > General > Startup and Shutdown > Workspaces
  5. Now, you can create or import a Project: a directory containing all files needed for a plug-in, for example the folder Python Sample Menu Command.
    • Import an existing Project (for example the Python Sample Menu Command): File -> New -> Project... > General
    • Create a new python Project: file > new > project > PyDev > PyDev project
    See Creating a Project in the pdev documentation for more infos.

Set up VW to debug using Aptana

The way the debug works is to use the remote debugger of Aptana: http://pydev.org/manual_adv_remote_debugger.html. Set up in Vectorworks the correct Python environment path:

  1. Vectorworks menu Tools -> Plug-ins -> Script Options : add an environment path to the needed Folder location:
    • Win example: D:\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013012902\pysrc
    • Mac example: /Applications/Aptana Studio 3/plugins/org.python.pydev_3.0.0.1388187472/pysrc
    Note
    You may need to change that to the place where you have installed the Aptana Studio application.
    PythonAptanaPyDevPathSetup.jpg
  2. Include an import to the PyDev remote debugger in your script. The Python Sample Menu Command contains commented code that enables PyDev debugger:
import pydevd
pydevd.settrace(suspend=False)
Warning
if your script fails it can be because the 'pydevd' module is not found. To fix that you must point Vectorworks' Python to the correct environment path to find the missing module.

Enable the remote debugger in Aptana

Then you go to Aptana Studio and enable the remote debugger (instructions under http://pydev.org/manual_adv_remote_debugger.html) and run your script in Vectorworks. You may need to enable the Debug perspective in Aptana before being able to enable the debug server, or the mentioned "green button" of the instructions will not be available:

  1. How to enable the Debug Perspective view:
    • Window > Open Perspective > Other > Debug: a new icon with a green bug will appear on the rightmost corner of the window (see screenshot below), this toggles the debug perspective
    • while in the Debug Perspective view, start the remote pydev debugger server: click on the green button with the bug and a P, which you'll find about the middle of the window (again screenshot below)
    PythonAptanaPyDevDebugServerSetup.jpg

See Also

Python basic information: Python

Personal tools
NamespacesFFFF

Variants
Actions
Advanced Search
See Also
Navigation
Toolbox