Getting py2exe to work with zope.interface

后端 未结 3 1473
星月不相逢
星月不相逢 2020-12-17 02:58

I have a Python app based on Twisted and PyGTK. Twisted itself depends on zope.interface, and I don\'t import it directly.

Unfortunately, when I try to run my app, t

相关标签:
3条回答
  • 2020-12-17 03:25

    I don't know if you ever solved this, or if it's even relevant to you anymore, but for future searchers, I found an easy way to fix the zope import problem here.

    Specifically, add an empty __init__.py file to the PYTHONDIR/Lib/site-packages/zope directory.

    I tested this with a twisted application, using this setup file:

    #!/usr/bin/env python
    '''
    File: setup.py
    Author: Spencer Rathbun
    Date: 07/24/2012
    Description: Setup file for py2exe, converts client python script into executable.
    '''
    from distutils.core import setup
    import py2exe
    
    INCLUDES = [
        ''
    ]
    
    PACKAGES = [
        'twisted'
    ]
    
    setup(
            name = 'client',
            description = '',
            version = '1.0',
    
            console = [
                {"script":"client.py",
                    "icon_resources":[
                        (1, "c:\python27\DLLs\py.ico")
                        ]
                    }
                ],
            zipfile = None,
    
            options = {"py2exe":
                {"compressed": 1,
                    "optimize": 1,
                    "ascii": 0,
                    "bundle_files": 1,
    
                    "packages": ','.join(PACKAGES),
                    "includes": ','.join(INCLUDES),
                    }
                }
            )
    

    Py2exe can use this to successfully create an executable for twisted now, since it depends upon zope.

    0 讨论(0)
  • 2020-12-17 03:26

    I've had this same problem with zope.interface and friends (zope.component, et al). Specifically it is a problem with how py2exe searches and discovers packages AND how the zope packages are installed.

    zope is a namespace package and as a result relies on some funky import logic in it's .pth files (see zope.interface-3.*.*-py2.*-nspkg.pth) in order to add it's sub-packages to python's path. Have a look at it in site-packages and you'll see what I mean.

    py2exe has problems "discovering" this kind of package.

    In the end what I did was manually repackage the various zope packages I was using into a stardard module setup in site-packages and then reran py2exe - which then discovered everything no problem. It's a PITA, but until py2exe is able to handle packaging edge cases and/or the zope packages are packaged in a py2exe friendly fashion, it's about the best you can do.

    0 讨论(0)
  • 2020-12-17 03:29

    I was facing this issue in creating a package using py2exe in Windows XP SP3. I figured out that py2exe was not determining the dependencies correctly.

    To solve this issue, I uninstalled my third party package(s) and installed them using following easy_install command

    easy_install -Z <your_package_name>

    The -Z option unzips the package details, and hence the content is not compressed. When you run py2exe now, it will correctly detect the dependencies.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题