Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:10:52+00:00 2026-06-15T12:10:52+00:00

I write in Python 3. I want to add plugins support to my program.

  • 0

I write in Python 3.

I want to add plugins support to my program. I don’t want to use heavy frameworks, so I deiced to write a minimal one by my self.

By the way, the plugins need to run by time. I don’t always unload and load the plugin when re-run — the plugins will lose all data.

My folder structs is here:

interfaces/
├── dummy
├── gmail
│   ├── __init__.py
│   └── __pycache__
│       └── __init__.cpython-33.pyc
└── hello
    ├── __init__.py
    └── __pycache__
        └── __init__.cpython-33.pyc

Then, I wrote a piece of code to load and execute the plugins:

#!/usr/bin/python3
import os
import imp

INTERFACES_FOLDER = './interfaces'
MAIN_MODULE = '__init__'

def search_plugins():
    plugins = []
    plugins_folders = os.listdir(INTERFACES_FOLDER)

    for i in plugins_folders:
        plugin_folder = os.path.join(INTERFACES_FOLDER, i)

        if not os.path.isdir(plugin_folder):
            continue
        if not MAIN_MODULE + '.py' in os.listdir(plugin_folder):
            continue

        info = imp.find_module(MAIN_MODULE, [plugin_folder])
        plugins.append({'name': i, 'info': info})
    return plugins


def load_plugin(plugin):
    return imp.load_module(MAIN_MODULE, *plugin["info"])


plugins_list = search_plugins()
plugins = []

for i in plugins_list:
    module = load_plugin(i)
    print(module)
    plugins.append(module)

print(plugins)

Outputs:

# it works!
<module '__init__' from './interfaces/gmail/__init__.py'>
<module '__init__' from './interfaces/hello/__init__.py'>

# what's wrong?
[<module '__init__' from './interfaces/hello/__init__.py'>, 
 <module '__init__' from './interfaces/hello/__init__.py'>]

As you see, when I loaded a plugin, everything is working correctly. But when I append them to the a list, different modules will became a same one.

What’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:10:52+00:00Added an answer on June 15, 2026 at 12:10 pm

    You import different modules, but with the same name (they are all called “init“). Python will, when you import the second module notice that you have already imported a module called “init” and return that.

    The module you should import is rather the “gmail” and “hello” modules. That might work.

    However, I’d urge you to reconsider about writing your own plugin system. It really isn’t that easy. A quick search finds several plugin systems, some slightweight, some not so much. Most have been abandoned, which is an indication that this isn’t so easy as you might think.

    The plugin system in Python that probably is the most widely used, also the most flexible and amongst the oldest, is the Zope Component Architecture. See also the docs. Note that in Python 3 you use class decorators instead of the class body statements.

    Another popular plugin system is the “entry points” of Distribute. That’s quite lightweight, although I don’t know if you can load or unload plugins with that.

    Others I have never looked at are Yapsy, one called “Plugins” that seem abandoned, another one called “PyPlugin” also abandoned, and one called “easy_plugins” which seem very new, and isn’t abandoned yet.

    And here is example code for a plugin manager.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I write program in python 2.7 and I want to run another script
I am new on Django and Python. I want to write a program with
I have a Python CLI program, with SQL database models and want to add
I usually write python in emacs. I'll often want to re-evaluate my file, which
As part of some WSGI middleware I want to write a python class that
Below is my json data. What I want to do is write a python
Let's say there are two python scripts that want to write data to the
I want to write a simple regular expression in Python that extracts a number
I write a lot of Python code where I just want to read a
I want to write text files with DOS/Windows line endings '\r\n' using python running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.