Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import custom python modules on Python 3.11+ #1687

Closed
greenaar opened this issue Apr 22, 2024 · 4 comments
Closed

Unable to import custom python modules on Python 3.11+ #1687

greenaar opened this issue Apr 22, 2024 · 4 comments

Comments

@greenaar
Copy link

greenaar commented Apr 22, 2024

Describe the bug
Errbot running on python 3.11 in docker, unable to load a python library into a plugin

To Reproduce
plugin code:

from lib.chatutils import ChatUtils
from errbot import BotPlugin, botcmd

chatutils = ChatUtils()

class MyTest(BotPlugin):
    """Perform system level commands"""

    @botcmd()
    def am_i_admin(self, msg, _):
        admin = chatutils.is_admin(msg)
        return f"{chatutils.handle(msg)} {admin}"

python library (in plugins/lib/chatutils.py)

import os
import re

class ChatUtils:
    """
    A collection of common utilities used throughout the repo
    """
    def is_admin(self, msg, admins):
        if self.handle(msg) in admins:
            return True
        return False

    def handle(self, msg):
        try:
            return str(msg.frm).split("/")[1]
        except:
            return msg.frm

Expected behavior
Errbot should load the plugin.

** Actual behavior **

2024-04-22 19:54:18,251 INFO     errbot.core               Some plugins failed to start during bot startup:

Traceback (most recent call last):
  File "/errbot-data/lib/python3.11/site-packages/errbot/plugin_manager.py", line 289, in _load_plugins_generic
    plugin_classes = plugin_info.load_plugin_classes(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/errbot-data/lib/python3.11/site-packages/errbot/plugin_info.py", line 100, in load_plugin_classes
    spec.loader.exec_module(modu1e)
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/errbot-data/eks-ops/errbot/plugins/mytest/mytest.py", line 5, in <module>
    import lib.chatutils
ModuleNotFoundError: No module named 'lib.chatutils'; 'lib' is not a package
Error: MyTest failed to activate: 'NoneType' object has no attribute 'is_activated'.

Environment (please complete the following information):

  • Errbot version: 6.2.0
  • OS version: Debian 12
  • Python version: Python 3.11.2
  • Using a virtual environment: yes
  • Using Docker: yes

Additional context

Config.py includes a reference to plugins, and sys.path via errbot returns:

Path: ['/errbot-data/code', '/errbot-data/code', '/errbot-data/bin', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/errbot-data/lib/python3.11/site-packages', '/errbot-data/lib/python3.11/site-packages/errbot/storage', '/errbot-data/eks-ops/errbot/backends/err-backend-slackv3/src/slackv3', '/errbot-data/lib/python3.11/site-packages/errbot/core_plugins', '/errbot-data/eks-ops/errbot/plugins/mytest', '/errbot-data/eks-ops/errbot/plugins/ops', '/errbot-data/eks-ops/errbot/plugins/Git', '/errbot-data/eks-ops/errbot/plugins']

This includes (last entry) the plugins/ dir in the search path.

@greenaar
Copy link
Author

Further context. Same code, duplicate errbot running under Python 3.10.12 - this does not occur.

Same code, running on Python 3.11.2 not inside a docker container, still occurs.

@greenaar greenaar changed the title ModuleNotFoundError: No module named 'lib.chatutils'; 'lib' is not a package ModuleNotFoundError: No module named 'lib.chatutils'; 'lib' is not a package (Python 3.11) Apr 23, 2024
@greenaar greenaar changed the title ModuleNotFoundError: No module named 'lib.chatutils'; 'lib' is not a package (Python 3.11) Unable to import custom python modules on Python 3.11+ May 13, 2024
@greenaar
Copy link
Author

Still no idea. Is this a python issue? A debian 12 issue? Something else? Next attempt will have to be something other than debian 12, to see if it's related to that particular bundling.

I guess imports like mentioned https://errbot.readthedocs.io/en/latest/user_guide/plugin_development/basics.html#python-submodules aren't that common?

@greenaar
Copy link
Author

Ok, further information -- this does not occur on Ubuntu 24.04, running python 3.12.3. It also doesn't occur on Ubuntu 22.04 running 3.10.12.

Something debian specific? Going to spin up a debian 12 host to validate.

@greenaar
Copy link
Author

Ok. it's not debian OR python related.

When loading the slack backend, this occurs. When using the Text or Discord backends, it does not. I'm moving this ticket to errbotio/err-backend-slackv3#105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant