Xpra: Ticket #833: pillow 2.8.x packaging on win32: workaround pkg_resources import

The loader code in PIL/_webp.py (which is called by the PIL/WebPImagePlugin.py looks like this:

def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    import imp, pkg_resources
    __file__ = pkg_resources.resource_filename(__name__, '_webp.pyd')
    __loader__ = None; del __bootstrap__, __loader__
    imp.load_dynamic(__name__,__file__)
__bootstrap__()

And we just can't import pkg_resources and its gazillions of dependencies, so the import fails.

I've successfully tested this hardcoded workaround (after copying the _webp.pyd by hand to the installation directory:

def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    print("bootstrap() file=%s" % __file__)
    print("bootstrap() name=%s" % __name__)
    import imp
    try:
        import pkg_resources
        __file__ = pkg_resources.resource_filename(__name__, '_webp.pyd')
        print("bootstrap() pkg_resources file=%s" % __file__)
    except:
        __file__ = "C:\\Program Files\\Xpra\\_webp.pyd"
        print("no pkg_resources, trying from %s" % __file__)
    __loader__ = None; del __bootstrap__, __loader__
    imp.load_dynamic(__name__,__file__)
__bootstrap__()


Sun, 05 Apr 2015 07:43:33 GMT - Antoine Martin: status changed

Here's a cleaner workaround:

def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    print("bootstrap() file=%s" % __file__)
    print("bootstrap() name=%s" % __name__)
    import imp
    try:
        import pkg_resources
        __file__ = pkg_resources.resource_filename(__name__, '_webp.pyd')
        print("bootstrap() pkg_resources file=%s" % __file__)
    except:
        import sys, os.path
        for p in sys.path:
            f = os.path.join(p, "_webp.pyd")
            print("testing %s" % f)
            if os.path.exists(f):
                __file__ = f
        print("no pkg_resources, trying from %s" % __file__)
    __loader__ = None; del __bootstrap__, __loader__
    imp.load_dynamic(__name__,__file__)
__bootstrap__()

Sun, 05 Apr 2015 08:17:00 GMT - Antoine Martin: status changed; resolution set

Turns out that we can just force include the webp plugin (r8922) and py2exe does everything for us!


Sat, 23 Jan 2021 05:07:22 GMT - migration script:

this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/833