Upgrade Official Odoo12 Image From py3.5 To py3.8
💡 This post is insightful for the following scenarios.
- Python Upgrade
- Docker Creation
- Odoo Dependencies
Background
Due to the updated project requirements, we need to use new third-party libraries that require a newer version of Python. However, the Python version provided in the official Odoo 12.0 Docker image is too outdated, so we need to upgrade the Python version from 3.5 to 3.8.
Here I will use pyenv to upgrade the python version. And the final dockerfile will be offered in the end.
Environment: odoo:12.0 (link)
Step
1. Install the dependencies for python 3.8
1 | # install the dependencies for python3.8 |
2. Set the environment variable $PYENV_ROOT for pyenv
Reason: the docker will be run by user “odoo”. Therefore, we should set up a python path that can be accessed by user “odoo”
1 | ENV PYENV_ROOT=/var/local/pyenv/ |
3. Install python 3.8 by pyenv
1 | # install python 3.8 |
4. Change python 3.5 -> python 3.8 for odoo binary file
The way to test if the odoo can run in odoo offcial docker image, is to input “odoo” and click “enter” button.
How do you know which python it is using? Let try!
Well. Now is easy. Just create a soft link to current python3.
1 | RUN rm /usr/bin/python3 && ln -s /var/local/pyenv/shims/python3 /usr/bin/python3 |
5. List all the python 3.5 package and try to install them into python 3.8 package
Use this command to see current package.
1 | # check current package |
Here comes some principle that I follow:
- For some packages you can not download it by pip, like odoo, you should completely move it from 3.5 package to 3.8 package, including package itself and its information (.egg-info file)
- For some packages version you can directly download and use, you should download it to avoid unexpected error.
- For some pacgage version you cannot download or cannot use, you should download the newest version.
1 | # install odoo dependencies |
6. Change to user “odoo”
If you forget to change current user, odoo will fail to start.
1 | USER odoo |
7. Build the docker image
1 | docker build -t UserName/RepName:TagName . |