Can not import my Custom Python Module with Tryton

Hello there,

I am working on integrating a custom Python module into my Tryton instance and am facing some challenges; I have Tryton Version 6.0 , Python Version 3.10 & Ubuntu 22.04

I have developed a Python module to extend Trytons functionality for a specific business need.;The module includes custom models and logic designed to interact with Trytons core. when attempting to load the module I am facing the following error message:

ImportError: cannot import name 'my_custom_model' from 'tryton.modules'

I have double checked the modules configuration and dependencies but have not been able to resolve the issue. I suspect it might be related to how the module is being registered or possibly an issue with version compatibility.

What are the best practices for ensuring a custom module is correctly registered with Tryton? Are there specific steps I might have missed in the configuration?

How can I verify that my custom module is compatible with the version of Tryton I am using? Are there common pitfalls or version mismatches that I should be aware of?

And last there are any recommended debugging techniques or tools for resolving import errors related to custom modules in Tryton? :thinking:
Also i have check this tutorial https://discuss.tryton.org/t/basic-tutorial-for-python witch is good

Thank you in advance for your assistance. :slightly_smiling_face:

I see two possible issues that could lead to such error message:

  • your custom module is not installed in trytond.modules
  • your custom module generates an error when being imported (like syntax error, wrong import etc.)

Also there is something strange with the error message because it is using tryton.modules instead of trytond.modules.

I would recommend following the module tutorial.

If you are using the standard cookiecutter template, your module version must have the same series number (2 first numbers) as the trytond target.

I personally do all debugging using just print statement (or run the server in verbose mode).