<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kodi.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Calebzor</id>
	<title>Official Kodi Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://kodi.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Calebzor"/>
	<link rel="alternate" type="text/html" href="https://kodi.wiki/view/Special:Contributions/Calebzor"/>
	<updated>2026-06-23T21:45:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://kodi.wiki/index.php?title=Archive:Debug_Python_Scripts_with_Eclipse&amp;diff=111235</id>
		<title>Archive:Debug Python Scripts with Eclipse</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Archive:Debug_Python_Scripts_with_Eclipse&amp;diff=111235"/>
		<updated>2015-12-29T10:04:36Z</updated>

		<summary type="html">&lt;p&gt;Calebzor: /* Identify where PyDev remote debugger Python files are */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]|[[Python development]]}}&lt;br /&gt;
&lt;br /&gt;
Here is a method you can adopt in order to use the Eclipse (multi-platforms) remote debugger with your Python scripts/plugin.&lt;br /&gt;
&lt;br /&gt;
Note: Follow this link [[HOW-TO debug Python Scripts|Debugging Python Scripts on Linux with WinPDB]] for more information if you prefer to use WinPDB instead.&lt;br /&gt;
&lt;br /&gt;
Note: The information provided herein is also applicable to user with [http://www.aptana.com/ Aptana Studio 3] installation which come pre-installed with pydev. For this case, you can skip to [[#Configure Pydev and Eclipse|Configure Pydev and Eclipse]] after the Aptana Studio 3 installation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prerequisite ==&lt;br /&gt;
* Any platform able to run [http://www.eclipse.org/downloads/ Eclipse IDE] (Windows 32bit-64bit, Mac Carbon 32bit-64bit, Mac Cocoa 32bit-64bit, Linux 32bit-64bit): it is the platform from where you will run the debugger IDE&lt;br /&gt;
* Python interpreter 2.4 (use the same version as XBMC or version &amp;lt;= 2.7 ) install on the machine running Eclipse&lt;br /&gt;
* Any platform running XBMC (Xbox, Linux, MACOSX, Windows): it is the platform running Python scripts/plugin connecting with the remote debugger.&lt;br /&gt;
:XBMC installed on Ubuntu (should work just fine on Windows and Mac too)&lt;br /&gt;
* [http://pydev.org/ Pydev] plugin for Eclipse IDE: Pydev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython development.&lt;br /&gt;
&lt;br /&gt;
== Prepare and Setup Eclipse ==&lt;br /&gt;
&lt;br /&gt;
=== Install Eclipse ===&lt;br /&gt;
* Download [http://www.eclipse.org/downloads/ Eclipse IDE] and install it&lt;br /&gt;
Note: in our example Eclipse Galileo (3.5.1) is used&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Install Pydev in Eclipse ===&lt;br /&gt;
* In Eclipse go in: &#039;&#039;Help&#039;&#039; -&amp;gt; &#039;&#039;Install New Software...&#039;&#039;&lt;br /&gt;
* Click on the &#039;&#039;Add&#039;&#039; button and add Pydev website as a source: http://pydev.org/updates&lt;br /&gt;
* You will see the window below:&lt;br /&gt;
[[File:EclipsePydevUpdate.png]]&lt;br /&gt;
* Check &#039;&#039;PyDev&#039;&#039; box and follow the steps in order to install PyDev&lt;br /&gt;
Note: in our example PyDev 1.5.5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Configure Pydev and Eclipse ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add Python Interpreter Path ====&lt;br /&gt;
* Go in &#039;&#039;Window&#039;&#039; -&amp;gt; &#039;&#039;Preferences&#039;&#039;&lt;br /&gt;
* &#039;&#039;Pydev&#039;&#039; then &#039;&#039;Interpreter - Python&#039;&#039;&lt;br /&gt;
* Click on button &#039;&#039;New...&#039;&#039;&lt;br /&gt;
* In the new prompt, enter the &#039;&#039;Interpreter Name: Python&#039;&#039;, and Browse for your Python Interpreter 2.4 &#039;&#039;python.exe&#039;&#039; file and select it. After that you should see something like this:&lt;br /&gt;
[[File:EclipsePydevPref.png|none]]&lt;br /&gt;
This will help in order to have Python code completion (except for XBMC modules)&lt;br /&gt;
&lt;br /&gt;
==== Add Pydev view to Eclipse ====&lt;br /&gt;
* On the top right corner click on the View button on select &#039;&#039;Others&#039;&#039;&lt;br /&gt;
[[File:EclipsePydevViewMenu.png]]&lt;br /&gt;
* Select Pydev then OK, a PyDev View Button should be now available on the top right corner&lt;br /&gt;
[[File:EclipsePydevViewMenu2.png]]&lt;br /&gt;
Use this view for your developments in Python for XBMC&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add Pydev Start/Stop debug server buttons ====&lt;br /&gt;
* In the menu bar select &#039;&#039;Window&#039;&#039; -&amp;gt; &#039;&#039;Customize perspective...&#039;&#039;, a window &#039;&#039;Customize Perspective - PyDev&#039;&#039; will open&lt;br /&gt;
* Select &#039;&#039;Command Groups Availability&#039;&#039; Tab&lt;br /&gt;
* Check &#039;&#039;Pydev Debug&#039;&#039; box and OK&lt;br /&gt;
* You should see 2 new buttons in your toolbar:&lt;br /&gt;
[[File:EclipsePydevDebugSrvButtons.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Setting the remote debugger port (optional) ====&lt;br /&gt;
If you do not want to use the default port (usually 5678) you can set it up:&lt;br /&gt;
* Go to &#039;&#039;Window&#039;&#039; -&amp;gt; &#039;&#039;Preferences&#039;&#039;&lt;br /&gt;
* &#039;&#039;Pydev&#039;&#039; then &#039;&#039;Debug&#039;&#039; you can define here the port and the timeout you want&lt;br /&gt;
&lt;br /&gt;
==== Setting up Predefined Completions (optional) ====&lt;br /&gt;
Many developers are accustom to using predefined completions when writing their code (eg. type-ahead). The standard Python completions are enabled by default when using these instructions, but the standard XBMC components will not be recognized appropriately (xbmc, xbmcgui, xbmcplugin, etc). &lt;br /&gt;
&lt;br /&gt;
In order to overcome this, you can run the [http://forum.kodi.tv/showthread.php?t=79070 PyDev Predefined Completions Creator addon] and [http://pydev.org/manual_101_interpreter.html#PyDevInterpreterConfiguration-PredefinedCompletions setup Eclipse] to reference this file:&lt;br /&gt;
# Download the &#039;PyDev Predefined Completions Creator&#039; Addon (eg. System &amp;gt; Settings &amp;gt; Addons &amp;gt; XBMC.org &amp;gt; Program Add-Ons)&lt;br /&gt;
# Navigate to the newly installed Addon (eg. Programs from the home screen)&lt;br /&gt;
# Open the context menu for newly installed addon and select &#039;Add-on Settings&#039;&lt;br /&gt;
# Set the location to save the help docs to and save the new settings (This can be anywhere on your system - we&#039;ll configure it in Eclipse later)&lt;br /&gt;
# Select the add-on to run it (the addon should run and close quickly)&lt;br /&gt;
# Open Eclipse and select Window &amp;gt; Preferences &amp;gt; PyDev &amp;gt; Interpreter - Python&lt;br /&gt;
# From the &#039;Predefined&#039; tab, click the new button and select the folder you created in the step above&lt;br /&gt;
# Press Apply / OK to ensure the changes are saved&lt;br /&gt;
&lt;br /&gt;
== Create a Python script/plugin for XBMC in Eclipse ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new PyDev Project ===&lt;br /&gt;
Most of the time when you are doing development, likely that you are running XBMC and Eclipse on the same platform; (The installed debugger described in this article actually can also work with a remote XBMC).&amp;lt;br\&amp;gt;&lt;br /&gt;
Let&#039;s say you already have scripts installed in XBMC script folder that you want to create a new PyDev project e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\XBMC\addons\myscript1&lt;br /&gt;
C:\XBMC\addons\myscript2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With myscript1 &amp;amp; myscript2 being sub-directories of &#039;&#039;C:\XBMC\addons&#039;&#039; each containing the Default.py scripts.&amp;lt;br\&amp;gt;&lt;br /&gt;
First you need to define the Python project workspace:&lt;br /&gt;
* &#039;&#039;File&#039;&#039; -&amp;gt; &#039;&#039;Switch Workspace&#039;&#039; -&amp;gt; &#039;&#039;Other...&#039;&#039;&lt;br /&gt;
* &#039;&#039;Browse&#039;&#039; to the parent directory of your script module i.e. &#039;&#039;C:\XBMC\addons&#039;&#039; in this example, select and OK&lt;br /&gt;
Then proceed to create the Python project:&lt;br /&gt;
* &#039;&#039;File&#039;&#039; -&amp;gt; &#039;&#039;New&#039;&#039; -&amp;gt; &#039;&#039;PyDev Project&#039;&#039;&lt;br /&gt;
: OR select below in case &#039;&#039;PyDev Project&#039;&#039; is not displayed&lt;br /&gt;
* &#039;&#039;File&#039;&#039; -&amp;gt; &#039;&#039;New&#039;&#039; -&amp;gt; &#039;&#039;Others&#039;&#039;; and Select &#039;&#039;Pydev&#039;&#039; then &#039;&#039;PyDev Project&#039;&#039;; Click &#039;&#039;Next&#039;&#039;&lt;br /&gt;
* Enter the name of your project e.g. xbmc_addons&lt;br /&gt;
* Uncheck option &#039;&#039;Use Default&#039;&#039;&lt;br /&gt;
* Browse to the directory of your scripts and select i.e. C:\XBMC\addons.&lt;br /&gt;
* Set &#039;&#039;Python&#039; as Project Type&lt;br /&gt;
* Select &#039;&#039;2.4 (XBMC Python version)&#039;&#039; for the grammar&lt;br /&gt;
* Select &#039;&#039;Don&#039;t configure PYTHONPATH (to be done manually later on)&#039;&#039;&lt;br /&gt;
* Click on &#039;&#039;Finish&#039;&#039; button&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Set the Python Path ===&lt;br /&gt;
* Right click on your new project and select &#039;&#039;Properties&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;PyDev - PYTHONPATH&#039;&#039; and click on &#039;&#039;Add source folder&#039;&#039;&lt;br /&gt;
* Select the source directory of your script, /xbmc_addons in our example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Import File System ===&lt;br /&gt;
Assuming you want to add in all the directories under C:\XBMC\addons&lt;br /&gt;
* Right click on your new project and select &#039;&#039;Import...&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;General&#039;&#039; and click on &#039;&#039;File System&#039;&#039;; then &#039;&#039;Next&#039;&#039;&lt;br /&gt;
* Browse to the source directory of your script (or plugin) e.g. C:\XBMC\addons&lt;br /&gt;
* Check the directory and files to be added&lt;br /&gt;
* Select &#039;&#039;Into folder: xbmc_addons&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;Options | &amp;lt;&amp;lt;Advanced | Create links in workspace&#039;&#039;&lt;br /&gt;
* Uncheck both the options i.e. &#039;&#039;Create virtual folders&#039;&#039; &amp;amp; &#039;&#039;Create link locations relative to;...&#039;&#039;&lt;br /&gt;
* Click on &#039;&#039;Finish&#039;&#039; button&lt;br /&gt;
Your source code is now recognized by Eclipse and you will have access to neat functionality such as code completion, link between source files, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Add Pydev Python source code (pysrc) to XBMC ===&lt;br /&gt;
XBMC needs to know where to find the PyDev remote python source file in order to communicate with the remote debugger of Eclipse.&lt;br /&gt;
&lt;br /&gt;
==== Identify where PyDev remote debugger Python files are ====&lt;br /&gt;
In later versions, you need to have started the debug server from Eclipse at least once for the following folder to show up. &lt;br /&gt;
&lt;br /&gt;
Python source files should be in you Eclipse installation directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;C:\...\eclipse\plugins\org.python.pydev.debug_1.5.5.2010030420\pysrc\&amp;lt;/pre&amp;gt;&lt;br /&gt;
In our case we use PyDev 1.5.5. With newer versions of PyDev, the directory structure changed.&lt;br /&gt;
&amp;lt;pre&amp;gt;C:\...\eclipse\plugins\org.python.pydev_3.6.0.201406232321\pysrc\&amp;lt;/pre&amp;gt;&lt;br /&gt;
Look for org.python.pydev.debug (not core)&lt;br /&gt;
&lt;br /&gt;
Instructions for Linux users:&lt;br /&gt;
&lt;br /&gt;
{{Collapse top}}&lt;br /&gt;
In new Eclipse versions on Linux, the standard eclipse installation (/usr/share/eclipse/plugins) does not contain the pydev files any more.&lt;br /&gt;
The easiest solution is to install the [[Add-on:Pydevd|pydevd-addon]].&amp;lt;br /&amp;gt;&lt;br /&gt;
To access this from your addon, your addon.xml has to contain &amp;lt;code&amp;gt;&amp;lt;import addon=&amp;quot;script.module.pydevd&amp;quot; version=&amp;quot;3.4.1&amp;quot;/&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
{{Collapse bottom}}&lt;br /&gt;
&lt;br /&gt;
==== Modify PyDev source in order to support XBMC paths ====&lt;br /&gt;
The pysrc code that came with Eclipse-pydev does not support XBMC paths (special://... or Q:/...) and the module would not find them making it impossible to insert breakpoints in such files.&lt;br /&gt;
&lt;br /&gt;
In order to add the support of XBMC paths, you will need to do a simple modification to the file &#039;&#039;pydevd_file_utils.py&#039;&#039; consisting on adding a line to each procedure that had a filename parameter (4 procedures in total). &lt;br /&gt;
Add a line like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 def _NormFile(filename):&lt;br /&gt;
     filename = xbmc.translatePath(filename)&lt;br /&gt;
     try:&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
The other three procedures are:&lt;br /&gt;
* def _NormFile(filename):&lt;br /&gt;
* def NormFileToServer(filename):&lt;br /&gt;
* def NormFileToClient(filename):&lt;br /&gt;
&lt;br /&gt;
of course you need the import directive at the top of the file:&lt;br /&gt;
&lt;br /&gt;
 import xbmc&lt;br /&gt;
&lt;br /&gt;
at the beginning of the module...&lt;br /&gt;
&lt;br /&gt;
==== Choose how XBMC will refer to Pydev debugging module ====&lt;br /&gt;
&lt;br /&gt;
You have 3 options as below:&lt;br /&gt;
* Option 1 - Refer from our python script directly the directory where pysrc is installed&lt;br /&gt;
* Option 2 - Copy pysrc in our script directory and refer it from our script&lt;br /&gt;
* Option 3 - Copy pysrc in XBMC Python install&lt;br /&gt;
* Option 4 - Use the pydev from the [[Add-on:Pydevd|pydevd-addon]]&lt;br /&gt;
&lt;br /&gt;
I am only going to show you the steps for &#039;&#039;Option 3&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
==== Copy pysrc in XBMC Python install ====&lt;br /&gt;
===== Option 3: (Suggested for Windows users) =====&lt;br /&gt;
* Copy the content of pysrc to:&lt;br /&gt;
&amp;lt;pre&amp;gt;XBMC\system\python\Lib\pysrc\&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Add an empty __init__.py file in it&lt;br /&gt;
&lt;br /&gt;
===== Option 4: (Suggested for Linux users) =====&lt;br /&gt;
Use the [[Add-on:Pydevd|pydevd-addon]] as described above. No action necessary. Option 3 does not work on Linux, because /usr/share/kodi/system/python/Lib is ignored.&lt;br /&gt;
&lt;br /&gt;
=== Add to your python script the code for remote debug ===&lt;br /&gt;
At the beginning of you Python script/plugin (usually Default.py) add the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
REMOTE_DBG = True&lt;br /&gt;
&lt;br /&gt;
# append pydev remote debugger&lt;br /&gt;
if REMOTE_DBG:&lt;br /&gt;
    # Make pydev debugger works for auto reload.&lt;br /&gt;
    # Note pydevd module need to be copied in XBMC\system\python\Lib\pysrc&lt;br /&gt;
    try:&lt;br /&gt;
        import pysrc.pydevd as pydevd # with the addon script.module.pydevd, only use `import pydevd`&lt;br /&gt;
    # stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console&lt;br /&gt;
        pydevd.settrace(&#039;localhost&#039;, stdoutToServer=True, stderrToServer=True)&lt;br /&gt;
    except ImportError:&lt;br /&gt;
        sys.stderr.write(&amp;quot;Error: &amp;quot; +&lt;br /&gt;
            &amp;quot;You must add org.python.pydev.debug.pysrc to your PYTHONPATH.&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this doesn&#039;t work and you are still getting the PYTHONPATH error you can try to:&lt;br /&gt;
&lt;br /&gt;
Replace:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    import pysrc.pydevd as pydevd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in the code snippet above with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    import sys&lt;br /&gt;
    sys.path.append(&#039;full_path_to_pysrc&#039;)&lt;br /&gt;
    import pydevd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case you have changed the default port you can replace the line with pydevd.settrace by this one:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        pydevd.settrace(&#039;localhost&#039;, port=5678, stdoutToServer=True, stderrToServer=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use REMOTE_DBG in order to activate or not the remote debugging&lt;br /&gt;
* port specifies the listening port number use between the client and the server&lt;br /&gt;
* Replace localhost by an IP address if XBMC and Eclipse are on 2 different machines&lt;br /&gt;
* stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console, you won&#039;t have to open xbmc.log file&lt;br /&gt;
&lt;br /&gt;
=== Run ===&lt;br /&gt;
* Go in Debug view (Eclipse: [[File:changeperspective.png]] / Debug ) and press on the start server button: [[File:EclipsePydevDebugSrvButtons.png]]&lt;br /&gt;
&lt;br /&gt;
* You will see in the console logs like:&lt;br /&gt;
&amp;lt;pre&amp;gt;Debug Server at port: 5678&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Start XBMC and run your script/plugin, you will see it as &amp;quot;Running&amp;quot; but paused&lt;br /&gt;
&lt;br /&gt;
* In Eclipse (Debug View) click on the Resume button (or F8), then you will see the program running in XBMC&lt;br /&gt;
&lt;br /&gt;
* You are now fully set up: You can set break-point, watch on variables, run step by step etc&lt;br /&gt;
&lt;br /&gt;
* Enjoy!&lt;br /&gt;
&lt;br /&gt;
=== Screenshot ===&lt;br /&gt;
&lt;br /&gt;
[[File:EclipsePydevDebugger.png]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Add-ons]]&lt;br /&gt;
* [[:Category:All add-ons]]&lt;br /&gt;
* [[3rd party add-on repositories]]&lt;br /&gt;
&#039;&#039;&#039;Development:&#039;&#039;&#039;&lt;br /&gt;
* [[Add-on development]]&lt;br /&gt;
* [[Addon Settings]]&lt;br /&gt;
* [[Python development]]&lt;br /&gt;
* [[Add-on repositories]]&lt;br /&gt;
* [[Official add-on repository]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;br /&gt;
[[Category:How-to]]&lt;br /&gt;
[[Category:Add-on development]]&lt;/div&gt;</summary>
		<author><name>Calebzor</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Archive:Debug_Python_Scripts_with_Eclipse&amp;diff=111234</id>
		<title>Archive:Debug Python Scripts with Eclipse</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Archive:Debug_Python_Scripts_with_Eclipse&amp;diff=111234"/>
		<updated>2015-12-29T09:59:51Z</updated>

		<summary type="html">&lt;p&gt;Calebzor: /* Add to your python script the code for remote debug */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]|[[Python development]]}}&lt;br /&gt;
&lt;br /&gt;
Here is a method you can adopt in order to use the Eclipse (multi-platforms) remote debugger with your Python scripts/plugin.&lt;br /&gt;
&lt;br /&gt;
Note: Follow this link [[HOW-TO debug Python Scripts|Debugging Python Scripts on Linux with WinPDB]] for more information if you prefer to use WinPDB instead.&lt;br /&gt;
&lt;br /&gt;
Note: The information provided herein is also applicable to user with [http://www.aptana.com/ Aptana Studio 3] installation which come pre-installed with pydev. For this case, you can skip to [[#Configure Pydev and Eclipse|Configure Pydev and Eclipse]] after the Aptana Studio 3 installation.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prerequisite ==&lt;br /&gt;
* Any platform able to run [http://www.eclipse.org/downloads/ Eclipse IDE] (Windows 32bit-64bit, Mac Carbon 32bit-64bit, Mac Cocoa 32bit-64bit, Linux 32bit-64bit): it is the platform from where you will run the debugger IDE&lt;br /&gt;
* Python interpreter 2.4 (use the same version as XBMC or version &amp;lt;= 2.7 ) install on the machine running Eclipse&lt;br /&gt;
* Any platform running XBMC (Xbox, Linux, MACOSX, Windows): it is the platform running Python scripts/plugin connecting with the remote debugger.&lt;br /&gt;
:XBMC installed on Ubuntu (should work just fine on Windows and Mac too)&lt;br /&gt;
* [http://pydev.org/ Pydev] plugin for Eclipse IDE: Pydev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython development.&lt;br /&gt;
&lt;br /&gt;
== Prepare and Setup Eclipse ==&lt;br /&gt;
&lt;br /&gt;
=== Install Eclipse ===&lt;br /&gt;
* Download [http://www.eclipse.org/downloads/ Eclipse IDE] and install it&lt;br /&gt;
Note: in our example Eclipse Galileo (3.5.1) is used&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Install Pydev in Eclipse ===&lt;br /&gt;
* In Eclipse go in: &#039;&#039;Help&#039;&#039; -&amp;gt; &#039;&#039;Install New Software...&#039;&#039;&lt;br /&gt;
* Click on the &#039;&#039;Add&#039;&#039; button and add Pydev website as a source: http://pydev.org/updates&lt;br /&gt;
* You will see the window below:&lt;br /&gt;
[[File:EclipsePydevUpdate.png]]&lt;br /&gt;
* Check &#039;&#039;PyDev&#039;&#039; box and follow the steps in order to install PyDev&lt;br /&gt;
Note: in our example PyDev 1.5.5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Configure Pydev and Eclipse ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add Python Interpreter Path ====&lt;br /&gt;
* Go in &#039;&#039;Window&#039;&#039; -&amp;gt; &#039;&#039;Preferences&#039;&#039;&lt;br /&gt;
* &#039;&#039;Pydev&#039;&#039; then &#039;&#039;Interpreter - Python&#039;&#039;&lt;br /&gt;
* Click on button &#039;&#039;New...&#039;&#039;&lt;br /&gt;
* In the new prompt, enter the &#039;&#039;Interpreter Name: Python&#039;&#039;, and Browse for your Python Interpreter 2.4 &#039;&#039;python.exe&#039;&#039; file and select it. After that you should see something like this:&lt;br /&gt;
[[File:EclipsePydevPref.png|none]]&lt;br /&gt;
This will help in order to have Python code completion (except for XBMC modules)&lt;br /&gt;
&lt;br /&gt;
==== Add Pydev view to Eclipse ====&lt;br /&gt;
* On the top right corner click on the View button on select &#039;&#039;Others&#039;&#039;&lt;br /&gt;
[[File:EclipsePydevViewMenu.png]]&lt;br /&gt;
* Select Pydev then OK, a PyDev View Button should be now available on the top right corner&lt;br /&gt;
[[File:EclipsePydevViewMenu2.png]]&lt;br /&gt;
Use this view for your developments in Python for XBMC&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add Pydev Start/Stop debug server buttons ====&lt;br /&gt;
* In the menu bar select &#039;&#039;Window&#039;&#039; -&amp;gt; &#039;&#039;Customize perspective...&#039;&#039;, a window &#039;&#039;Customize Perspective - PyDev&#039;&#039; will open&lt;br /&gt;
* Select &#039;&#039;Command Groups Availability&#039;&#039; Tab&lt;br /&gt;
* Check &#039;&#039;Pydev Debug&#039;&#039; box and OK&lt;br /&gt;
* You should see 2 new buttons in your toolbar:&lt;br /&gt;
[[File:EclipsePydevDebugSrvButtons.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Setting the remote debugger port (optional) ====&lt;br /&gt;
If you do not want to use the default port (usually 5678) you can set it up:&lt;br /&gt;
* Go to &#039;&#039;Window&#039;&#039; -&amp;gt; &#039;&#039;Preferences&#039;&#039;&lt;br /&gt;
* &#039;&#039;Pydev&#039;&#039; then &#039;&#039;Debug&#039;&#039; you can define here the port and the timeout you want&lt;br /&gt;
&lt;br /&gt;
==== Setting up Predefined Completions (optional) ====&lt;br /&gt;
Many developers are accustom to using predefined completions when writing their code (eg. type-ahead). The standard Python completions are enabled by default when using these instructions, but the standard XBMC components will not be recognized appropriately (xbmc, xbmcgui, xbmcplugin, etc). &lt;br /&gt;
&lt;br /&gt;
In order to overcome this, you can run the [http://forum.kodi.tv/showthread.php?t=79070 PyDev Predefined Completions Creator addon] and [http://pydev.org/manual_101_interpreter.html#PyDevInterpreterConfiguration-PredefinedCompletions setup Eclipse] to reference this file:&lt;br /&gt;
# Download the &#039;PyDev Predefined Completions Creator&#039; Addon (eg. System &amp;gt; Settings &amp;gt; Addons &amp;gt; XBMC.org &amp;gt; Program Add-Ons)&lt;br /&gt;
# Navigate to the newly installed Addon (eg. Programs from the home screen)&lt;br /&gt;
# Open the context menu for newly installed addon and select &#039;Add-on Settings&#039;&lt;br /&gt;
# Set the location to save the help docs to and save the new settings (This can be anywhere on your system - we&#039;ll configure it in Eclipse later)&lt;br /&gt;
# Select the add-on to run it (the addon should run and close quickly)&lt;br /&gt;
# Open Eclipse and select Window &amp;gt; Preferences &amp;gt; PyDev &amp;gt; Interpreter - Python&lt;br /&gt;
# From the &#039;Predefined&#039; tab, click the new button and select the folder you created in the step above&lt;br /&gt;
# Press Apply / OK to ensure the changes are saved&lt;br /&gt;
&lt;br /&gt;
== Create a Python script/plugin for XBMC in Eclipse ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create a new PyDev Project ===&lt;br /&gt;
Most of the time when you are doing development, likely that you are running XBMC and Eclipse on the same platform; (The installed debugger described in this article actually can also work with a remote XBMC).&amp;lt;br\&amp;gt;&lt;br /&gt;
Let&#039;s say you already have scripts installed in XBMC script folder that you want to create a new PyDev project e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
C:\XBMC\addons\myscript1&lt;br /&gt;
C:\XBMC\addons\myscript2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With myscript1 &amp;amp; myscript2 being sub-directories of &#039;&#039;C:\XBMC\addons&#039;&#039; each containing the Default.py scripts.&amp;lt;br\&amp;gt;&lt;br /&gt;
First you need to define the Python project workspace:&lt;br /&gt;
* &#039;&#039;File&#039;&#039; -&amp;gt; &#039;&#039;Switch Workspace&#039;&#039; -&amp;gt; &#039;&#039;Other...&#039;&#039;&lt;br /&gt;
* &#039;&#039;Browse&#039;&#039; to the parent directory of your script module i.e. &#039;&#039;C:\XBMC\addons&#039;&#039; in this example, select and OK&lt;br /&gt;
Then proceed to create the Python project:&lt;br /&gt;
* &#039;&#039;File&#039;&#039; -&amp;gt; &#039;&#039;New&#039;&#039; -&amp;gt; &#039;&#039;PyDev Project&#039;&#039;&lt;br /&gt;
: OR select below in case &#039;&#039;PyDev Project&#039;&#039; is not displayed&lt;br /&gt;
* &#039;&#039;File&#039;&#039; -&amp;gt; &#039;&#039;New&#039;&#039; -&amp;gt; &#039;&#039;Others&#039;&#039;; and Select &#039;&#039;Pydev&#039;&#039; then &#039;&#039;PyDev Project&#039;&#039;; Click &#039;&#039;Next&#039;&#039;&lt;br /&gt;
* Enter the name of your project e.g. xbmc_addons&lt;br /&gt;
* Uncheck option &#039;&#039;Use Default&#039;&#039;&lt;br /&gt;
* Browse to the directory of your scripts and select i.e. C:\XBMC\addons.&lt;br /&gt;
* Set &#039;&#039;Python&#039; as Project Type&lt;br /&gt;
* Select &#039;&#039;2.4 (XBMC Python version)&#039;&#039; for the grammar&lt;br /&gt;
* Select &#039;&#039;Don&#039;t configure PYTHONPATH (to be done manually later on)&#039;&#039;&lt;br /&gt;
* Click on &#039;&#039;Finish&#039;&#039; button&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Set the Python Path ===&lt;br /&gt;
* Right click on your new project and select &#039;&#039;Properties&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;PyDev - PYTHONPATH&#039;&#039; and click on &#039;&#039;Add source folder&#039;&#039;&lt;br /&gt;
* Select the source directory of your script, /xbmc_addons in our example&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Import File System ===&lt;br /&gt;
Assuming you want to add in all the directories under C:\XBMC\addons&lt;br /&gt;
* Right click on your new project and select &#039;&#039;Import...&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;General&#039;&#039; and click on &#039;&#039;File System&#039;&#039;; then &#039;&#039;Next&#039;&#039;&lt;br /&gt;
* Browse to the source directory of your script (or plugin) e.g. C:\XBMC\addons&lt;br /&gt;
* Check the directory and files to be added&lt;br /&gt;
* Select &#039;&#039;Into folder: xbmc_addons&#039;&#039;&lt;br /&gt;
* Select &#039;&#039;Options | &amp;lt;&amp;lt;Advanced | Create links in workspace&#039;&#039;&lt;br /&gt;
* Uncheck both the options i.e. &#039;&#039;Create virtual folders&#039;&#039; &amp;amp; &#039;&#039;Create link locations relative to;...&#039;&#039;&lt;br /&gt;
* Click on &#039;&#039;Finish&#039;&#039; button&lt;br /&gt;
Your source code is now recognized by Eclipse and you will have access to neat functionality such as code completion, link between source files, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Add Pydev Python source code (pysrc) to XBMC ===&lt;br /&gt;
XBMC needs to know where to find the PyDev remote python source file in order to communicate with the remote debugger of Eclipse.&lt;br /&gt;
&lt;br /&gt;
==== Identify where PyDev remote debugger Python files are ====&lt;br /&gt;
Python source files should be in you Eclipse installation directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;C:\...\eclipse\plugins\org.python.pydev.debug_1.5.5.2010030420\pysrc\&amp;lt;/pre&amp;gt;&lt;br /&gt;
In our case we use PyDev 1.5.5. With newer versions of PyDev, the directory structure changed.&lt;br /&gt;
&amp;lt;pre&amp;gt;C:\...\eclipse\plugins\org.python.pydev_3.6.0.201406232321\pysrc\&amp;lt;/pre&amp;gt;&lt;br /&gt;
Look for org.python.pydev.debug (not core)&lt;br /&gt;
&lt;br /&gt;
Instructions for Linux users:&lt;br /&gt;
&lt;br /&gt;
{{Collapse top}}&lt;br /&gt;
In new Eclipse versions on Linux, the standard eclipse installation (/usr/share/eclipse/plugins) does not contain the pydev files any more.&lt;br /&gt;
The easiest solution is to install the [[Add-on:Pydevd|pydevd-addon]].&amp;lt;br /&amp;gt;&lt;br /&gt;
To access this from your addon, your addon.xml has to contain &amp;lt;code&amp;gt;&amp;lt;import addon=&amp;quot;script.module.pydevd&amp;quot; version=&amp;quot;3.4.1&amp;quot;/&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
{{Collapse bottom}}&lt;br /&gt;
&lt;br /&gt;
==== Modify PyDev source in order to support XBMC paths ====&lt;br /&gt;
The pysrc code that came with Eclipse-pydev does not support XBMC paths (special://... or Q:/...) and the module would not find them making it impossible to insert breakpoints in such files.&lt;br /&gt;
&lt;br /&gt;
In order to add the support of XBMC paths, you will need to do a simple modification to the file &#039;&#039;pydevd_file_utils.py&#039;&#039; consisting on adding a line to each procedure that had a filename parameter (4 procedures in total). &lt;br /&gt;
Add a line like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 def _NormFile(filename):&lt;br /&gt;
     filename = xbmc.translatePath(filename)&lt;br /&gt;
     try:&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
The other three procedures are:&lt;br /&gt;
* def _NormFile(filename):&lt;br /&gt;
* def NormFileToServer(filename):&lt;br /&gt;
* def NormFileToClient(filename):&lt;br /&gt;
&lt;br /&gt;
of course you need the import directive at the top of the file:&lt;br /&gt;
&lt;br /&gt;
 import xbmc&lt;br /&gt;
&lt;br /&gt;
at the beginning of the module...&lt;br /&gt;
&lt;br /&gt;
==== Choose how XBMC will refer to Pydev debugging module ====&lt;br /&gt;
&lt;br /&gt;
You have 3 options as below:&lt;br /&gt;
* Option 1 - Refer from our python script directly the directory where pysrc is installed&lt;br /&gt;
* Option 2 - Copy pysrc in our script directory and refer it from our script&lt;br /&gt;
* Option 3 - Copy pysrc in XBMC Python install&lt;br /&gt;
* Option 4 - Use the pydev from the [[Add-on:Pydevd|pydevd-addon]]&lt;br /&gt;
&lt;br /&gt;
I am only going to show you the steps for &#039;&#039;Option 3&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
==== Copy pysrc in XBMC Python install ====&lt;br /&gt;
===== Option 3: (Suggested for Windows users) =====&lt;br /&gt;
* Copy the content of pysrc to:&lt;br /&gt;
&amp;lt;pre&amp;gt;XBMC\system\python\Lib\pysrc\&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Add an empty __init__.py file in it&lt;br /&gt;
&lt;br /&gt;
===== Option 4: (Suggested for Linux users) =====&lt;br /&gt;
Use the [[Add-on:Pydevd|pydevd-addon]] as described above. No action necessary. Option 3 does not work on Linux, because /usr/share/kodi/system/python/Lib is ignored.&lt;br /&gt;
&lt;br /&gt;
=== Add to your python script the code for remote debug ===&lt;br /&gt;
At the beginning of you Python script/plugin (usually Default.py) add the following code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
REMOTE_DBG = True&lt;br /&gt;
&lt;br /&gt;
# append pydev remote debugger&lt;br /&gt;
if REMOTE_DBG:&lt;br /&gt;
    # Make pydev debugger works for auto reload.&lt;br /&gt;
    # Note pydevd module need to be copied in XBMC\system\python\Lib\pysrc&lt;br /&gt;
    try:&lt;br /&gt;
        import pysrc.pydevd as pydevd # with the addon script.module.pydevd, only use `import pydevd`&lt;br /&gt;
    # stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console&lt;br /&gt;
        pydevd.settrace(&#039;localhost&#039;, stdoutToServer=True, stderrToServer=True)&lt;br /&gt;
    except ImportError:&lt;br /&gt;
        sys.stderr.write(&amp;quot;Error: &amp;quot; +&lt;br /&gt;
            &amp;quot;You must add org.python.pydev.debug.pysrc to your PYTHONPATH.&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this doesn&#039;t work and you are still getting the PYTHONPATH error you can try to:&lt;br /&gt;
&lt;br /&gt;
Replace:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    import pysrc.pydevd as pydevd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in the code snippet above with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    import sys&lt;br /&gt;
    sys.path.append(&#039;full_path_to_pysrc&#039;)&lt;br /&gt;
    import pydevd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the case you have changed the default port you can replace the line with pydevd.settrace by this one:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        pydevd.settrace(&#039;localhost&#039;, port=5678, stdoutToServer=True, stderrToServer=True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Use REMOTE_DBG in order to activate or not the remote debugging&lt;br /&gt;
* port specifies the listening port number use between the client and the server&lt;br /&gt;
* Replace localhost by an IP address if XBMC and Eclipse are on 2 different machines&lt;br /&gt;
* stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console, you won&#039;t have to open xbmc.log file&lt;br /&gt;
&lt;br /&gt;
=== Run ===&lt;br /&gt;
* Go in Debug view (Eclipse: [[File:changeperspective.png]] / Debug ) and press on the start server button: [[File:EclipsePydevDebugSrvButtons.png]]&lt;br /&gt;
&lt;br /&gt;
* You will see in the console logs like:&lt;br /&gt;
&amp;lt;pre&amp;gt;Debug Server at port: 5678&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Start XBMC and run your script/plugin, you will see it as &amp;quot;Running&amp;quot; but paused&lt;br /&gt;
&lt;br /&gt;
* In Eclipse (Debug View) click on the Resume button (or F8), then you will see the program running in XBMC&lt;br /&gt;
&lt;br /&gt;
* You are now fully set up: You can set break-point, watch on variables, run step by step etc&lt;br /&gt;
&lt;br /&gt;
* Enjoy!&lt;br /&gt;
&lt;br /&gt;
=== Screenshot ===&lt;br /&gt;
&lt;br /&gt;
[[File:EclipsePydevDebugger.png]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Add-ons]]&lt;br /&gt;
* [[:Category:All add-ons]]&lt;br /&gt;
* [[3rd party add-on repositories]]&lt;br /&gt;
&#039;&#039;&#039;Development:&#039;&#039;&#039;&lt;br /&gt;
* [[Add-on development]]&lt;br /&gt;
* [[Addon Settings]]&lt;br /&gt;
* [[Python development]]&lt;br /&gt;
* [[Add-on repositories]]&lt;br /&gt;
* [[Official add-on repository]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;br /&gt;
[[Category:How-to]]&lt;br /&gt;
[[Category:Add-on development]]&lt;/div&gt;</summary>
		<author><name>Calebzor</name></author>
	</entry>
</feed>