views:

761

answers:

3

Hi, 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?

+1  A: 

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="[email protected]",
       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
monkut
+1  A: 

Hi, yes, that's what I've been doing - added needed imports ;). I was just wondering, maybe someone has done it better. Such "plugin system" should be probably a part of pyInstaller/py2exe.

uhzzre
This should be comment to the answer.
voyager
+1  A: 

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.

Giovanni Bajo
I was thinking about plugin system for my standalone application. I have application created with pyInstaller. I want to create plugins for this application. The problem is when plugin imports something that was not imported in original application - import fails.
uhzzre
So generally the best would be if:- plugins do not contain modules that are already in binary application- plugins contain modules that are not present in application- import first tries to import from main application, if fails from plugin modules
uhzzre
That is exactly what PyInstaller does. Have you tried it?
Giovanni Bajo