Last modified 7 months ago
Last modified on 10/13/11 14:23:19
Packaging from setuptools entry point
setuptools/pkg_resources have a feature called Automatic Script Creation. If your Python package is using this feature to create console or gui scripts, you will have a hard time packaging this with PyInstaller. The reason for this is that the generated script basically looks like this one:
from pkg_resources import load_entry_point load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
So it does not import you module, but out-tasks this to load_entry_point. PyInstaller can not detect this.
The Recipe
Put the following snippet into you .spec file:
def Entrypoint(dist, group, name, scripts=None, pathex=None, hookspath=None, excludes=None): import pkg_resources scripts = scripts or [] pathex = pathex or [] # get the entry point ep = pkg_resources.get_entry_info(dist, group, name) # insert path of the egg at the verify front of the search path pathex = [ep.dist.location] + pathex # script name must not be a valid module name to avoid name clashes on import script_path = os.path.join(BUILDPATH, name+'-script.py') print "writjng script for entry point", dist, group, name fp = open(script_path, 'w') try: print >>fp, "import", ep.module_name print >>fp, "%s.%s()" % (ep.module_name, '.'.join(ep.attrs)) finally: fp.close() return Analysis(scripts + [script_path], pathex, hookspath, excludes)
Now instead of running Analysis() on your script, simply run Entrypoint on the entry point definition:
a = Entrypoint('pdftools.pdfposter', 'console_scripts', 'pdfposter', [os.path.join(HOMEPATH,'support','_mountzlib.py'), os.path.join(CONFIGDIR,'support','useUnicode.py'), ])
