Odoo 10 setup and debug in Eclipse
by Stanislav on Tuesday Jan 24, 2017
Hi everyone, I’m writing this post to describe an installation process of Odoo and its debug in Eclipse IDE on Windows. There are articles exist on the internet dedicated to this theme, but none of them covers this task in relation to Odoo version 10. Odoo 10 differs from the other versions, plus it ships with another set of setup files, so if you’re interested in detailed description of Odoo setup in Eclipse – this post may be helpful.
We need the source code of Odoo to make the debugging possible, so let’s start with Odoo 10 source code downloading: you can do this either by going to GitHub or just by downloading it from Odoo’s official site. In first case you’ll have to wait much longer since there’s the entire commit history is downloaded as well. Let’s say that Odoo source is downloaded to C:/Users/Lenovo/git/Odoo.
Odoo 10 is based on Python 2.7 and if you don’t have it installed locally – please do it using the official site of Python. Odoo requires a few Python libs (such as Babel, ebaysdk, lxml, python-ldap etc.) that are not shipped within a standard Python bundle, these libs should be installed manually to your Python. Luckily Pip package manager is already persist in downloaded Python distributive and you can easily use it to install required packages. Within Odoo distribution directory you can find requirements.txt file that keeps all package names + version to be installed. In this way go to %Python_dir%/Scripts folder where pip.exe is located and run the following command (assuming requirements.txt is placed in current dir):
pip install -r requirements.txt
After that almost all packages required to Odoo will be installed. Since we’re on Windows we need to install win32service as well. This module is not stored in Pip repository, it should be downloaded from the sourceforge directly taking in mind the 2.7 Python version. I’d recommend to download and run exe-file exactly from this source, since we’ve tried to take win32service from the other repositories, none of them worked.
Now it’s time to start Eclipse. Install (if not yet) PyDev plugin: go to Window -> Preferences -> Install/Update -> Available Software Sites. Fill in new site name, e.g. “PyDev” and its URL http://pydev.org/updates.
Next step is to set up Python Interpreter that will be used by PyDev. Interpreter itself is a local dir where the Python is installed. Go to Window –> Preferences –> PyDev –> Interpreters –> Python Interpreter –> New, then specify a path to your Python installation and click Save. As an example, assume that installation dir is C:/Python27 then PyDev will search for its subdirs to find all modules location and add them to System PYTHONPATH, the final look of the interpreter view:
When the Python interpreter is installed, we can move further. Next step is to create new PyDev project in Eclipse. It’s pretty straightforward, pick Python project type, specify project name and select the Python interpreter we’ve just created. If you wish to attach Odoo source code to current project (we will need it since we’ll have custom code that uses Odoo modules and project’s main module starter.py refers to odoo module as well – see below), then open project Properties window, navigate to PyDev –PYTHONPATH, go to External Libraries path, add Odoo source folder (source folder is the one we’ve created while cloning the Odoo Git repo):
Good, we’re almost done. Let’s configure Debug configuration. Create a new Python Run, select the project we’ve created, define main module. Main module is the python file that actually starts Odoo. This file called starter.py and has the content:
import odoo if __name__ == "__main__": odoo.cli.main()
In previous versions of Odoo (earlier than 10) this main module was called openerp-server.py, in Odoo 10 it is missing, so there’s need to create a new one, e.g. starter.py. Main tab of Debug configuration looks so:
The final thing we should define on Debug configuration form is to add Odoo configuration file that keeps information about database URL, user name, DB password + source code locations. This file odoo.conf can be found under Odoo distribution dir, the minimal and sufficient version of it may look as following:
[options] db_host = False db_port = False db_user = odoo db_password = False addons_path = C:\Users\Lenovo\git\odoo\addons,C:\workspace_o
Now we need to specify for our Debug configuration a path to current Odoo configuration file. Go to Arguments tab –> Program arguments –> Variables –> Edit Variables –> New. Here create a new variable with any name, the Value of the variable should be a path to the config file: --config=%PATH%/odoo.conf.
Finally you can run you Debug configuration, set up some breakpoint and see how the Odoo (as well as your custom module) execution stops for debug purposes, the debug trace and program variables can be watched.