Question

how to create a good plugin engine for standalone executables created with pyInstaller, py2exe or similar tools?

I do not have experience with py2exe, but pyInstaller uses an import hook to import packages from it's compressed repository. Of course I am able to import dynamically another compressed repository created with pyInstaller and execute the code - this may be a simple plugin engine.

Problems appears when the plugin (this what is imported dynamically) uses a library that is not present in original repository (never imported). This is because import hook is for the original application and searches for packages in original repository - not the one imported later (plugin package repository).

Is there an easy way to solve this problem? Maybe there exist such engine?

Was it helpful?

Solution

When compiling to exe, your going to have this issue.

The only option I can think of to allow users access with thier plugins to use any python library is to include all libraries in the exe package.

It's probably a good idea to limit supported libraries to a subset, and list it in your documentation. Up to you.

I've only used py2exe.

In py2exe you can specify libraries that were not found in the search in the setup.py file.

Here's a sample:

from distutils.core import setup
import py2exe

setup (name = "script2compile",
       console=['script2compile.pyw'],
       version = "1.4",
       author = "me",
       author_email="somemail@me.com",
       url="myurl.com",
       windows = [{
                    "script":"script2compile.pyw",
                    "icon_resources":[(1,"./ICONS/app.ico")]  # Icon file to use for display
                 }],
       # put packages/libraries to include in the "packages" list
       options = {"py2exe":{"packages": [   "pickle",
                                            "csv",
                                            "Tkconstants",
                                            "Tkinter",
                                            "tkFileDialog",
                                            "pyexpat",
                                            "xml.dom.minidom",
                                            "win32pdh",
                                            "win32pdhutil",
                                            "win32api",
                                            "win32con",
                                            "subprocess", 
                                        ]}} 

       )

import win32pdh
import win32pdhutil
import win32api

OTHER TIPS

PyInstaller does have a plugin system for handling hidden imports, and ships with several of those already in. See the webpage (http://www.pyinstaller.org) which says:

The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. Check our compatibility list of SupportedPackages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top