Open DaniilDigtyar opened 1 year ago
Hey, Daniil!
Thanks for bringing this issue to our attention. I've been working to understand what's going on.
I discovered, just like you mentioned, that Odoo modules in /opt/odoo/addons
aren't not present in the venv. I've also realized that this behavior isn't limited to an LXC container - it also occurs on a production server.
I noticed the same results when running these two scripts:
from odoo import modules
modules.get_modules()
and
import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
print(len(installed_packages_list))
using:
/home/odoo/pyenv/versions/odoo/bin/python
interpreter/home/odoo/pyenv/versions/odoo/bin/python3.8
interpreterpython
interpreter with the venv odoo
loaded./home/odoo/pyenv/versions/odoo/bin/python
interpreter via SSH (ssh debug.local -t "/home/odoo/pyenv/versions/odoo/bin/python -c '(...)'
I am wondering if it is possible that this behavior is related to the fact that these modules, despite -or precisely because- they belong to Odoo core, are not straightforward available in a virtualenv, but through Odoo logic.
For instance, consider this example:
from odoo import models, fields, api
class InstanceCalendarEvent(models.Model):
_inherit = 'calendar.event'
This returns an error, emphasizing that the import should start with 'odoo.addons'.:
assert self.__module__.startswith('odoo.addons.'), \
AssertionError: Invalid import of __main__.InstanceCalendarEvent, it should start with 'odoo.addons'.
To help us get a handle on this, could you provide a little more information?
I'm also intrigued about the use of the SFTP protocol. It's the only piece that it's unfamiliar to me.
Thanks again for reporting!!
Salut!
Thanks for the answer.
The problem is not related to execution, odoo detects all the module even if they are not in the venv because we specify the two addons paths in the odoo.conf
addons_path = /opt/odoo_modules, /opt/odoo/addons
My problem is from the python interpreter, that only uses the modules found in the venv.
I use the IDE Pycharm, but it happens too in Visual Code, and when using this plugin it detects that these odoo core module are missing (when in execution they are not) and marks them as errors.
The SFTP protocol is how the IDE copies the venv locally to be able to use it.
I talked with other coopdevs employees, and it seems like I'm the only one that uses the remote interpreter or this plugin, because it assures me that I'm working in the exact same interpreter as the local lxc and makes suggestions and detects errors before I execute on the machine.
Ah! That sounds more familiar.
It seems more like a problem related to PyCharm/Odoo IDE configuration than with the odoo-role
, doesn't it?
I've been taking a look at the Odoo IDE repository and I've seen some issues that might refer to a similar case. Have you asked there?
Regarding PyCharm, I can't remember the details right now, but it seems to me that there was a need to add/map folders for it to be aware of. For VsCode, I just documented how to use it for debugging in devenv
yesterday, and it seems to work like a charm.
I believe that the fact that these addons are not directly available under the interpreter is the expected behavior.
Maybe you could give SSH a shot, using PyCharm's Remote Development
feature?
Hey, @DaniilDigtyar, how did it go? Did the documentation help you?
Do you agree that this isn't a problem from odoo-role
and, thus, this issue can be closed?
When using the remote python interpreter of the lxc container, some Odoo modules are not added by default to the venv.
Remote Python 3.7.7 (sftp://odoo@odoo-ce.local:22/home/odoo/pyenv/versions/odoo/bin/python3.7)
All the modules located in
/opt/odoo/addons
these are all the core Odoo modulesaccount, crm, l10n_es...
are not added to the venv and not found by the interpreter because they are not installed via pip.The modules located in
/opt/odoo/odoo/addons
, (base and all the testing modules) are added.To fix this, I copy all the modules in
/opt/odoo/addons
to the/home/odoo/pyenv/versions/odoo/lib/python3.7/site-packages/odoo/addons
folder.Don't know I is something with my configuration that I do wrong, feedback is apreciated.