Skip to content

Instantly share code, notes, and snippets.

@Shadow6363
Created December 11, 2012 04:59
Show Gist options
  • Save Shadow6363/4255985 to your computer and use it in GitHub Desktop.
Save Shadow6363/4255985 to your computer and use it in GitHub Desktop.
PyInstaller Dynamic Demo
PluginTest/
dist/
plugin_test/
plugin_test
*
src/
plugin_test.py
plugins/
platform_printer.py
pyinstaller src/plugin_test.py
cp -R src/plugins dist/plugin_test/
dist/plugin_test/plugin_test
import sys
def print_platform():
print sys.platform
import imp, os, sys
if __name__ == '__main__':
plugins_folder = os.path.dirname(sys.executable) + os.sep + 'plugins'
if not plugins_folder in sys.path:
sys.path.append(plugins_folder)
for root, dirs, files in os.walk(plugins_folder):
for module_file in files:
module_name, module_extension = os.path.splitext(module_file)
if module_name != '__init__' and module_extension == os.extsep + "py":
try:
module_hdl, path_name, description = imp.find_module(module_name)
plugin_module = imp.load_module(module_name, module_hdl, path_name,
description)
plugin_module.print_platform()
finally:
if module_hdl:
module_hdl.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment