Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo custom module with external Python library

I created an Odoo Module in Python using the Python library ujson. I installed this library on my development server manually with pip install ujson.

Now I want to install the Module on my live server. Can I somehow tell the Odoo Module to install the ujson library when it is installed? So I just have to add the Module to my addons path and install it via the Odoo Web Interface?

Another reason to have this automated would be if I like to share my custom module, so others don't have to install the library manually on their server.

Any suggestions how to configure my Module that way? Or should I just include the library's directory in my module?

like image 613
IstaLibera Avatar asked Jun 10 '26 20:06

IstaLibera


2 Answers

You should try-except the import to handle problems on odoo server start:

try:
    from external_dependency import ClassA
except ImportError:
    pass

And for other users of your module, extend the external_dependencies in your module manifest (v9 and less: __openerp__.py; v10+: __manifest__.py), which will prompt a warning on installation:

"external_dependencies": {
    'python': ['external_dependency']
},

Big thanks goes to Ivan and his Blog

like image 72
CZoellner Avatar answered Jun 16 '26 21:06

CZoellner


Thank you for your help, @Walid Mashal and @CZoellner, you both pointed me to the right direction.

I solved this task now with the following code added to the __init__.py of my module:

import pip
try:
    import ujson
except ImportError:
    print('\n There was no such module named -ujson- installed')
    print('xxxxxxxxxxxxxxxx installing ujson xxxxxxxxxxxxxx')
    pip.main(['install', 'ujson'])
like image 26
IstaLibera Avatar answered Jun 16 '26 20:06

IstaLibera