cx_Freeze不包括dbm

时间:2015-11-12 23:12:55

标签: python

有没有人有一个适用于我的程序的setup.py文件?我的整个节目是here。无论如何导入其中一个dbm? 我尝试过很多东西让我的exe工作。这只是我尝试的最后一个。

这是我用来将程序转换为exe文件的setup.py文件。

from cx_Freeze import setup, Executable

packages = []
for dbmodule in ['dbhash', 'gdbm', 'dbm', 'dumbdbm', 'gnu', 'ndbm', 'dumb',
                 'dbm.gnu', 'dbm.ndbm', 'dbm.dumb', 'gnudbm', 'ndbmdbm']:
    try:
        __import__(dbmodule)
    except ImportError:
        pass
    else:
        # If we found the module, ensure it's copied to the build directory.
        packages.append(dbmodule)
build_exe_options = {'packages': ['os','sys','shelve']}
setup(name='RockPaperScissors-V2',
      options = {"build_exe": build_exe_options},
      version='0.1',
      description='Classic game of Rock Paper Scissors',
      executables = [Executable("RockPaperScissorsV2.py")])

尝试运行我的exe程序时出现此错误。

E:\Python3 Files\RockPaperScissors\build\exe.win32-3.4>RockPaperScissorsV2
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27
, in <module>
    exec(code, m.__dict__)
  File "RockPaperScissorsV2.py", line 201, in <module>
  File "RockPaperScissorsV2.py", line 153, in start_game
  File "RockPaperScissorsV2.py", line 120, in intro
  File "C:\Python34\lib\shelve.py", line 239, in open
    return DbfilenameShelf(filename, flag, protocol, writeback)
  File "C:\Python34\lib\shelve.py", line 223, in __init__
    Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
  File "C:\Python34\lib\dbm\__init__.py", line 75, in open
    raise ImportError("no dbm clone found; tried %s" % _names)
ImportError: no dbm clone found; tried ['dbm.gnu', 'dbm.ndbm', 'dbm.dumb']

1 个答案:

答案 0 :(得分:2)

最后,经过多次测试,我找到了答案。实际上这很简单。我所要做的就是将dbm添加到转换文件中的包中。

from cx_Freeze import setup, Executable

build_exe_options = {'packages': ['dbm']}
setup(name='RockPaperScissors-V2',
      version='0.1',
      options = {"build_exe": build_exe_options},
      description='Classic game of Rock Paper Scissors',
      executables = [Executable("RockPaperScissorsV2.py")])