How To Run Odoo 12 With Virtualenv
On Ubuntu 18.o4 or Debian 9
When developing Odoo 12 or another version on a local machine, I never used package installation. But, I using virtualenv to run it. Many advantages can we obtained if we develop Odoo with virtualenv. One of them is we can run various versions of Odoo on one machine simultaneously with distinguishing ports.
In this case, I use Ubuntu 18.04 and can work on Debian 9. You can try this tutorial to another operating system, but you need to search for any dependencies of Odoo on your operating system.
Odoo 12 Preparation.
- Download Odoo 12 source code from Odoo repository on Github https://github.com/odoo/odoo or you can do
git clone
- Extract downloaded file. We only use
addons/
directory,odoo/
directory,odoo-bin
file, andrequirements.txt
file. Make sure that directory structure like the image below.
- Install python3 pip and virtualenv with
sudo apt install python3-pip python3-venv
- Create virtualenv with
python3 -m venv <venv-directory>
You can create virtualenv on same directory or different directory. In this tutorial, I use same directory as the Odoo directory.
- Install other dependencies for Odoo
sudo apt install python3-dev libxml2-dev libxslt1-dev libldap2-dev libssl-dev libsasl2-dev
- Activate virtualenv with
. <venv-directory>/bin/activate
- Upgrade pip with
pip install --upgrade pip
We need to upgrade pip module because the old pip can’t work properly with dependencies. - Install all Odoo dependencies in the
requirements.txt
withpip install -r requirements.txt
PostgreSQL Preparation.
- Install Postgresql with
sudo apt install postgresql
- Switch to
postgres
account withsudo su — postgres
and typepsql
- Create a new user on Postgresql for Odoo. In this tutorial I use
odoo12
as username andodoo
as a password. Type this SQL commandCREATE USER odoo12 WITH CREATEDB ENCRYPTED PASSWORD 'odoo';
- Quit from
postgres
account then configure postgresql pg_hba file. Open pg_hba withsudo nano /etc/postgresql/<postgresql-version>/main/pg_hba.conf
add a command for Odoo custom config like image below.
- Restart your postgresql service with
sudo service postgresql restart
Set Odoo Config.
Create a configuration file for Odoo named odoo.conf
(or whatever you want). Fill in the file with the command below.
[options]
db_host = 127.0.0.1
db_port = 5432
db_user = odoo12
db_password = odoo
http_port = 8069
longpolling_port = 8072
addons_path = addons
You can read https://www.odoo.com/documentation/12.0/setup/deploy.html for other options of configuration. Also, you can set other port for http_port
and longpolling_port
.
And you just need activating virtualenv then run ./odoo-bin -c odoo.conf
Open your browser and type localhost:8069
or ip_address:port
That’s it. Thanks for reading. If you have a question, please write in the comments section.
PS: I do not participate in the Medium Partner Program. If you like my article, this is how you can show it. Thanks.