modpython: ImportError when trying to load my module #696

Closed
opened 2026-10-05 04:39:15 +02:00 by adam · 1 comment
Owner

I created a znc script usind modpython. When I try to import a second helper script into my custom module, I get an import error for the script I'm trying to import. Here's an example of the issue:

mymodule.py

import znc
import mymodulehelper # throws an ImportError exception
class foo:
    def OnLoad(self, args, msg):
        self.PutModule('Loaded....')
        # ...

folder structure

| ~/.znc/modules
    | mymodule.py
    | mymodulehelper.py

Any help would be greatly appreciated.

I created a znc script usind modpython. When I try to import a second helper script into my custom module, I get an import error for the script I'm trying to import. Here's an example of the issue: `mymodule.py` ``` python import znc import mymodulehelper # throws an ImportError exception class foo: def OnLoad(self, args, msg): self.PutModule('Loaded....') # ... ``` folder structure ``` | ~/.znc/modules | mymodule.py | mymodulehelper.py ``` Any help would be greatly appreciated. <!-- github-sync-id:148916183 -->
adam closed this issue 2026-10-05 04:39:15 +02:00
Author
Owner

ZNC doesn't add path to modules to sys.path, you can do it yourself.

import sys
sys.path.append('/path/to/helpers')
import mymodulehelper

It's better to be a different directory from ~/.znc/modules/ though. Files in ~/.znc/modules/ are intended to be loaded from ZNC as a module, not from python using import.

ZNC doesn't add path to modules to `sys.path`, you can do it yourself. ``` py import sys sys.path.append('/path/to/helpers') import mymodulehelper ``` It's better to be a different directory from `~/.znc/modules/` though. Files in `~/.znc/modules/` are intended to be loaded from ZNC as a module, not from python using `import`. <!-- github-comment-id:210990229 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#696