Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

python - Getting py2exe to work with zope.interface

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, the following error ends up in the error log:

Traceback (most recent call last):
  File "tasks.py", line 4, in <module>
  File "ui\__init__.pyc", line 14, in <module>
  File "twistedpythonlog.pyc", line 17, in <module>
ImportError: No module named zope.interface
Traceback (most recent call last):
  File "tasks.py", line 4, in <module>
  File "ui\__init__.pyc", line 14, in <module>
  File "twistedpythonlog.pyc", line 17, in <module>
ImportError: No module named zope.interface
Traceback (most recent call last):
  File "tasks.py", line 4, in <module>
  File "ui\__init__.pyc", line 14, in <module>
  File "twistedpythonlog.pyc", line 17, in <module>
ImportError: No module named zope.interface

I've tried adding every combination of zope.interface and zope to INCLUDES and PACKAGES, but doing so only gives me this build time error:

running py2exe
*** searching for required modules ***
C:Python26libsite-packagespy2exeuild_exe.py:16: DeprecationWarning: the sets module is deprecated
  import sets
Traceback (most recent call last):
  File "setup.py", line 75, in <module>
    'gtk/*.ui'
  File "C:Python26libdistutilscore.py", line 152, in setup
    dist.run_commands()
  File "C:Python26libdistutilsdist.py", line 975, in run_commands
    self.run_command(cmd)
  File "C:Python26libdistutilsdist.py", line 995, in run_command
    cmd_obj.run()
  File "C:Python26libsite-packagespy2exeuild_exe.py", line 243, in run
    self._run()
  File "C:Python26libsite-packagespy2exeuild_exe.py", line 296, in _run
    self.find_needed_modules(mf, required_files, required_modules)
  File "C:Python26libsite-packagespy2exeuild_exe.py", line 1306, in find_needed_modules
    mf.import_hook(f)
  File "C:Python26libsite-packagespy2exemf.py", line 719, in import_hook
    return Base.import_hook(self,name,caller,fromlist,level)
  File "C:Python26libsite-packagespy2exemf.py", line 136, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "C:Python26libsite-packagespy2exemf.py", line 204, in find_head_package
    raise ImportError, "No module named " + qname
ImportError: No module named zope

My setup.py is:

from distutils.core import setup
import py2exe

def find_data_files(source,target,patterns):
    # I've elided this, I doubt it's relevant to the problem
    # ...

INCLUDES = [
    'cairo',
    'pango',
    'pangocairo',
    'atk',
    'gobject',
    'gio',
]

PACKAGES = [
    'encodings',
]

setup(
    name = 'MyApp',
    description = 'My Application',
    version = '1.0',

    windows = [
                  {
                      'script': os.path.join('ui','tasks.py'),
                      'icon_resources': [
                            (1, os.path.join(
                                'ui','data','iconpack.ico'))
                        ],
                  }
              ],

    options = {
                  'py2exe': {
                      'packages': ','.join(PACKAGES),
                      'includes': ','.join(INCLUDES),
                  }
              },

    data_files = find_data_files(
                    'ui', 'ui', [
                        'data/*',
                        'gtk/*.ui'
                    ])

)

How do I get py2exe to build this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:python27DLLspy.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...