How to install and use Eclipse for Python development and debugging with OpenERP

How to install Eclipse on Windows

  • Download and install the Java SE JDK
  • Download and install Eclipse Classic 3.5.1 or later from http://eclipse.org
  • In Eclipse, install PyDev by going to Help / Install new software / Add.
    • Name: Pydev
    • Location: pydev.org/updates.
    • Then tick PyDev, Next, Install PyDev for Eclipse.
    • After it has installed, go to Windows / Preference / Pydev / Interpreter – Python; go to Python Interpreters.
    • Click the “Auto Config” button. It should list a lot of directories. Make sure you tick the directory for PyDev; it is probably the first or last directory in the list, and probably the only one not yet ticked.

How to install Eclipse on Centos 5.5

These instructions are for Centos 5.5.

  • Install the GUI Desktop, e.g.:
    # yum groupinstall 'X Window System'
    # yum groupinstall 'Gnome Desktop environment'
  • Install Java:
    # yum install java
  • Install Eclipse:
    # yum install eclipse-platform
  • Run Eclipse in the GUI environment.
    # init 5
  • Go to Help / Updates / Find and Install…; select Search for new features to install.
  • Click on New Remote Site.
    • Name: Pydev
    • Location: pydev.org/updates.
  • Hit Finish.
  • Expand PyDev. Select PyDev; you do not need to select ‘PyDev Mylyn Integration’.
  • Hit Finish; it should download and install PyDev.
  • After it has installed, go to Windows / Preference / Pydev / Interpreter – Python; go to Python Interpreters.
  • Click the “Auto Config” button. It should list a lot of directories. Make sure you tick the directory for PyDev; it is probably the first or last directory in the list, and probably the only one not yet ticked.

How to setup up Ecplise for debugging on Linux

If you are logged into a graphical desktop, you can debug OpenERP using the following procedure:

  • Copy ~openerp/.openerp_serverrc to your home directory.
  • Edit /<your-home-directory>/.openerp_serverrc; change the entries for root_path and addons_path as appropriate, e.g.:
    • root_path = /<your-home-directory>/eclipse.workspace/OpenERP/src
    • addons_path = /<your-home-directory>/eclipse.workspace/OpenERP/src/addons
    • Create a new project in Eclipse.
    • Copy all the OpenERP source into the src directory of the project, including all the sub-directories.
    • It is easier if you start Eclipse in the directory where your project lives. There may be a better way to do this, but you could:
      • Stop Eclipse
      • Create a shell script, called something such as start_eclipse, in your PATH with contents like this:
        #!/bin/sh
        cd $HOME/work/eclipse.workspace/OpenERP/src
        exec eclipse
      • Then run start_eclipse from your command-line (or tell XMing to run it).
      • Add all the modules and code to the project:
        • Right-click on the src directory in the PyDev Package Explorer.
        • Go to New / File / Advanced and tick Link to file in the file system.
        • Click on Browse and add openerp-server.py.
        • Do the same for all the other *.py files in the source directory.
        • Click on the src directory in the PyDev Package Explorer.
        • Go to New / Folder / Advanced and tick Link to folder in the file system.
        • Click on Browse and add the addons directory.
        • Do the same for all the other directories.
      • In the top right, select the Debug perspective.
      • Setup a Debug configuration in Eclipse:
        • In Eclipse, go to Run / Debug….
        • Select Python Run.
        • Click the New button.
        • Give the configuration a Name.
        • Select your OpenERP project.
        • For Main Module, browse to openerp-server.py
        • On the Arguments tab, add start-up arguments that you may want; see /etc/init.d/openerp-server for arguments.
          E.g. you may use: –logfile=/var/log/openerp-server.log –log-level=debug.
        • Apply the changes and Close.
      • Set breakpoints in your source files as desired.
      • To start debugging, press the Debug toolbar icon or go to Run/Debug… and press the Debug button.

How to run Eclipse on Linux in a window on Windows using X-Windows

To turn your Linux’s installation of Eclipse from your Windows PC, download and install the XMing server. This actually works quite well – the responsiveness is better than running a Gnome desktop inside a Virtual Machine. Run Xlaunch and tell it to run eclipse or your start_eclipse shell script in a multi-window environment.

Install Code Snippets

Download and install code snippets from: http://code.google.com/p/openerp-eclipse-template/

Code snippets are shortcuts for adding template code.

Gotcha’s

If you create a file in Eclipse, the Windows version, and it saves in DOS format (as opposed to Unix format end-of-lines), then OpenERP 5 will not detect or load the module. You can use Unix’s file command to tell you which files have these unwanted CRLF’s:

E.g. these files had problems (note the CRLF line terminators notes):

/home/phil/openerp/addons/my_product_kit # file *.py *.xml
__init__.py:              ASCII Java program text, with CRLF line terminators
my_product_kit.py:        ASCII Java program text, with CRLF line terminators

but these did not:

/home/phil/openerp/addons/my_product_kit # file works/*
works/__init__.py:         ASCII English text
works/my_territory.py:     ASCII Java program text
works/my_territory.xml:    ASCII text
works/__terp__.py:         ASCII text

IDE’s that you can use for Python

Here’s a list of IDE’s that you can use for Python:

  • Eclipse on Windows
  • Eclipse on Linux
  • Aptana – based on Eclipse
  • Netbeans
  • Visual Studio 2010 with IronPython

Python Code Editors

Here’s a list of editors for Python code:

  • vim
  • gedit

How to set up Samba

How to set up Samba on Centos 5 so you can share a drive from a Linux box to a Windows PC. This is so that you can run Eclipse on your PC to edit files on your Linux OpenERP server.

# service smb start
# smbpasswd -a philu
# setsebool -P samba_enable_home_dirs
# setsebool -P samba_export_all_rw on
# chcon -R -t samba_share_t /home/philu

Then mapped a network drive from Windows, using:

  • User: \username
  • Share: \\openerp.example.com\username

Debugging

Use your IDE’s tools, or the Python debugger: http://docs.python.org/library/pdb.html

See Also

Advertisements
This entry was posted in OpenERP. Bookmark the permalink.

One Response to How to install and use Eclipse for Python development and debugging with OpenERP

  1. Latha says:

    I am getting proxy authentication error while installing Pydev software. The redirecting link is http://pydev.org/updates/content.xml

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s