In this article, you will learn how to install python packages automatically with the installation of Odoo Modules.
For example, if we have created an Odoo module that uses python packages, then it will raise an error on installation. This error occurs due to system does not find the required python packages which an Odoo module needs.
Read More: How to Create Custom Modules in Odoo8
Install Python Libraries on Installation of Odoo Modules
To overcome this issue we need to install Python packages automatically when we install the Odoo Module. Below is the step-by-step guide you need to follow.
Read More: How to Create Custom Modules in Odoo13
- Create a python file in your Odoo module and name it "setup.py".
- Copy below code snippet in the above file.
- Register your newly created python file "setup.py" in __init.py__ file.
How to Install Python Packages using Python Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Install_Packages: | |
""" | |
This Class installs required Packages or library | |
""" | |
get_pckg = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) | |
installed_packages = [r.decode().split('==')[0] for r in get_pckg.split()] | |
# List of your required packages | |
required_packages = ['packages_1', 'packages_2', 'packages_3', 'packages_4'] | |
for packg in required_packages: | |
if packg in installed_packages: | |
pass | |
else: | |
print('installing package %s' % packg) | |
os.system('pip3 install ' + packg) | |
0 Comments