Python Debugging/ja: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
No edit summary
No edit summary
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
Pythonはオープンソースのスクリプティングエンジンであり、エンジンに接続してデバッグ可能な多くの無料および有料のIDEが存在します。インターネットでそれらを検索して試してみることができます。Maybe you can find an easier way to make it work.
Pythonはオープンソースのスクリプティングエンジンです。このエンジンに接続してデバッグ可能な、多くの無料および有料のIDEが存在します。インターネットでそれらを検索して試してみることができます。さらに簡単なデバッグの方法が見つかるかもしれません。
{{LocationMain|category=LocationPYSpecial|specific=}}
{{LocationMain|category=LocationPYSpecial|specific=}}
<div class="rightmenu">
<div class="rightmenu">
Line 6: Line 6:
== Aptana Studioでのデバッグ ==
== Aptana Studioでのデバッグ ==


I have experimented with [http://www.aptana.com Aptana Studio] which is a version of [http://en.wikipedia.org/wiki/Eclipse_(software) Eclipse].
ここでは、[http://en.wikipedia.org/wiki/Eclipse_(software) Eclipse]のバージョンである[http://www.aptana.com Aptana Studio]を使用します。


ApatanaはPythonプロジェクトの管理ができるIDEです。また、Vectorworksのようなリモートのpythonエンジンをデバッグできます。It includes [http://pydev.org/ PyDev] for that which, by itself, is a plug-in to do python in Eclipse.
Apatanaは、Pythonプロジェクトの管理が行えるIDEです。また、Vectorworksのようなリモートのpythonエンジンをデバッグできます。Apatanaには、Eclipseでpythonを実行するためのプラグイン[http://pydev.org/ PyDev]が含まれています。


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


== Aptanaを設定する  ==
== Aptanaを設定する  ==


# 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.
# Python 3.3 runtime ([http://www.python.org/download/ download])をインストールします。 I’ll hook Aptana to this version later. 技術的には必要ありませんが、こうすることで編集中にApatanaがシンタックスエラーをレポートすることができるようになります。
# Install Aptana Studio 3 ([http://www.aptana.com/products/studio3/download.html download]).
# 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):
# Aptanaは多くの言語をサポートしています。初回だけ、Pythonインタプリタ (上で述べた[http://en.wikipedia.org/wiki/PyDev pydev]プラグイン) を設定する必要があります:
#:* '''Preferences > PyDev > Interpreters > Python Interpreter'''
#:* '''Preferences > PyDev > Interpreters > Python Interpreter'''
#:* click on '''Advanced Auto-Config'''
#:* 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.  
#:* 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.
#:: 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:
# ''Workspace''を指定します: これは''Projects''を格納する場所であり、このケースではコードのあるプラグインフォルダです。Aptanaのデフォルトでは、アプリケーションは起動するごとにワークスペースを選択するようユーザに促します:
#:* When prompted at start: choose a directory outside any Vectorworks path.
#:* 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.  
#:* When you need to manually change the path: '''File > Switch Workspace > Other...''': choose a directory outside any Vectorworks path.  
Line 28: Line 28:
#:: 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".  
#:: 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'''  
#:: 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]].
# ここで、''Project''を作成または取り込むことができます:これはプラグインに必要なすべてのファイルのあるディレクトリです。例: [[Python Sample Menu Command]].
#:* Import an existing ''Project'' (for example the [[Python Sample Menu Command]]): '''File -> New -> Project... > General'''
#:* 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'''
#:* Create a new python ''Project'': '''file > new > project > PyDev > PyDev project'''
Line 35: Line 35:
== VWを設定する  ==
== VWを設定する  ==


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:
デバッグの方法として、Apatanaのリモートデバッガを使用します: http://pydev.org/manual_adv_remote_debugger.html.  VectorworksでPythonの正しい環境パスを設定してください:
#: Vectorworks menu '''Tools -> Plug-ins -> Script Options''' : add an environment path to the needed Folder location:  
#: Vectorworksメニュー '''ツール -> プラグイン -> スクリプトオプション''' : 必要なフォルダへの環境パスを追加します:  
#:* Win example: D:\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013012902\pysrc
#:* Windowsの例: 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
#:* Macの例: /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.
#:; 注意: Apatana Studioをインストールした場所に適宜変更する必要があります。
#: [[Image:PythonAptanaPyDevPathSetup.jpg]]
#: [[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:
# スクリプトにPyDevリモートデバッガのimportを記述します。[[Python Sample Menu Command]] には、PyDevデバッガを有効にするコメント付きのコードが含まれています:
<code lang="py">
<code lang="py">
import pydevd
import pydevd
Line 47: Line 47:
</code>
</code>


; 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.
; 注意: スクリプトが失敗した場合は「pydevd」モジュールが見つからないのが原因です。環境パスでVectorworksのPythonを指定して、モジュールが見つかるようにしてください。


== リモートデバッガを有効にする ==
== リモートデバッガを有効にする ==


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:  
Aptana Studioでリモートデバッガを有効にして (手順はこちら: http://pydev.org/manual_adv_remote_debugger.html) Vectorworksでスクリプトを実行します。 デバッグサーバを有効にする前に、AptanaでDebug Perspectiveを有効にしなければならない場合があります。こうしないと、手順にある「緑色のボタン」が使用できません:  
# Enable the Debug Perspective view:  
# 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
#* '''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
Line 57: Line 57:
#: [[Image:PythonAptanaPyDevDebugServerSetup.jpg]]
#: [[Image:PythonAptanaPyDevDebugServerSetup.jpg]]


== See Also ==
== 関連項目 ==


Python basic information: [[Python]]
Python basic information: [[Python]]

Latest revision as of 05:24, 21 December 2017

Pythonはオープンソースのスクリプティングエンジンです。このエンジンに接続してデバッグ可能な、多くの無料および有料のIDEが存在します。インターネットでそれらを検索して試してみることができます。さらに簡単なデバッグの方法が見つかるかもしれません。

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

Aptana Studioでのデバッグ

ここでは、EclipseのバージョンであるAptana Studioを使用します。

Apatanaは、Pythonプロジェクトの管理が行えるIDEです。また、Vectorworksのようなリモートのpythonエンジンをデバッグできます。Apatanaには、Eclipseでpythonを実行するためのプラグインPyDevが含まれています。

リモートデバッグの方法についてはこちら: http://pydev.org/manual_adv_remote_debugger.html

Aptanaを設定する

  1. Python 3.3 runtime (download)をインストールします。 I’ll hook Aptana to this version later. 技術的には必要ありませんが、こうすることで編集中にApatanaがシンタックスエラーをレポートすることができるようになります。
  2. Aptana Studio 3 (download)をインストールします。
  3. Aptanaは多くの言語をサポートしています。初回だけ、Pythonインタプリタ (上で述べたpydevプラグイン) を設定する必要があります:
    • 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. Workspaceを指定します: これはProjectsを格納する場所であり、このケースではコードのあるプラグインフォルダです。Aptanaのデフォルトでは、アプリケーションは起動するごとにワークスペースを選択するようユーザに促します:
    • 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. ここで、Projectを作成または取り込むことができます:これはプラグインに必要なすべてのファイルのあるディレクトリです。例: 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.

VWを設定する

デバッグの方法として、Apatanaのリモートデバッガを使用します: http://pydev.org/manual_adv_remote_debugger.html. VectorworksでPythonの正しい環境パスを設定してください:

  1. Vectorworksメニュー ツール -> プラグイン -> スクリプトオプション : 必要なフォルダへの環境パスを追加します:
    • Windowsの例: D:\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013012902\pysrc
    • Macの例: /Applications/Aptana Studio 3/plugins/org.python.pydev_3.0.0.1388187472/pysrc
    注意
    Apatana Studioをインストールした場所に適宜変更する必要があります。
  2. スクリプトにPyDevリモートデバッガのimportを記述します。Python Sample Menu Command には、PyDevデバッガを有効にするコメント付きのコードが含まれています:
import pydevd
pydevd.settrace(suspend=False)
注意
スクリプトが失敗した場合は「pydevd」モジュールが見つからないのが原因です。環境パスでVectorworksのPythonを指定して、モジュールが見つかるようにしてください。

リモートデバッガを有効にする

Aptana Studioでリモートデバッガを有効にして (手順はこちら: http://pydev.org/manual_adv_remote_debugger.html) Vectorworksでスクリプトを実行します。 デバッグサーバを有効にする前に、AptanaでDebug Perspectiveを有効にしなければならない場合があります。こうしないと、手順にある「緑色のボタン」が使用できません:

  1. 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
  2. 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)

関連項目

Python basic information: Python