cx_freeze no dbm clone found

This is the place for queries that don't fit in any of the other categories.

cx_freeze no dbm clone found

Postby metulburr » Fri May 23, 2014 4:59 pm

I am trying to use cx_freeze to compile an exe on windows and freeze executables in linux. Yes i know there is py2exe, i have already done it in py2exe, but i am now trying to figure out cxfreeze's method since that freezes an executable in linux as well.

Code: Select all
C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master\build\exe.win32-2.7>ls
SDL.dll               pyexpat.pyd                   pygame.mask.pyd
SDL_image.dll         pygame._arraysurfarray.pyd    pygame.mixer.pyd
SDL_mixer.dll         pygame._numericsndarray.pyd   pygame.mixer_music.pyd
SDL_ttf.dll           pygame._numericsurfarray.pyd  pygame.mouse.pyd
_ctypes.pyd           pygame.base.pyd               pygame.movie.pyd
_hashlib.pyd          pygame.bufferproxy.pyd        pygame.overlay.pyd
_multiprocessing.pyd  pygame.cdrom.pyd              pygame.pixelarray.pyd
_socket.pyd           pygame.color.pyd              pygame.rect.pyd
_ssl.pyd              pygame.constants.pyd          pygame.rwobject.pyd
bz2.pyd               pygame.display.pyd            pygame.scrap.pyd
game.exe              pygame.draw.pyd               pygame.surface.pyd
jpeg.dll              pygame.event.pyd              pygame.surflock.pyd
libfreetype-6.dll     pygame.fastevent.pyd          pygame.time.pyd
libogg-0.dll          pygame.font.pyd               pygame.transform.pyd
libpng12-0.dll        pygame.gfxdraw.pyd            python27.dll
library.zip           pygame.image.pyd              select.pyd
libtiff.dll           pygame.imageext.pyd           smpeg.dll
libvorbis-0.dll       pygame.joystick.pyd           unicodedata.pyd
libvorbisfile-3.dll   pygame.key.pyd                zlib1.dll

C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master\build\exe.win32-2.7>


upon execution of game.exe the traceback is:
Code: Select all
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "game.py", line 33, in <module>
  File "C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master\data\tools.py", line 20, in save
    db = shelve.open(DB.path)
  File "C:\Python27\lib\shelve.py", line 239, in open
    return DbfilenameShelf(filename, flag, protocol, writeback)
  File "C:\Python27\lib\shelve.py", line 222, in __init__
    import anydbm
  File "C:\Python27\lib\anydbm.py", line 53, in <module>
    raise ImportError, "no dbm clone found; tried %s" % _names
ImportError: no dbm clone found; tried ['dbhash', 'gdbm', 'dbm', 'dumbdbm']


I have tried adding this to the beginning of my setup
Code: Select all
for i in ['dbhash', 'gdbm', 'dbm', 'dumbdbm']:
    try:
        eval('import '+i)
    except:
        pass

which i had the same thing happen, it ran through but i got the same error

Someone said a solution was to add dbm to packages list, but that is for python3.x causing an import errror on python2.x

here is my setup.py file:
Code: Select all
import sys
from cx_Freeze import setup, Executable

build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

base = None
if sys.platform == "win32":
    base = "Win32GUI"
   
for i in ['dbhash', 'gdbm', 'dbm', 'dumbdbm']:
    try:
        eval('import '+i)
    except:
        pass

includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
    'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
    'Tkconstants', 'Tkinter']
packages = ['anydbm']
path = []


GUI2Exe_Target_1 = Executable(
    script = "game.py",
    initScript = None,
    base = base,
    #targetDir = r"dist",
    targetName = "game.exe",
    compress = False,
    copyDependentFiles = False,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = None
)

setup(
    version = "0.1",
    description = "No Description",
    author = "No Author",
    name = "cx_Freeze Sample File",
    options = {
        "build_exe": {
            "includes": includes,
            "excludes": excludes,
            "packages": packages,
            "path": path
            }
        },
    executables = [GUI2Exe_Target_1]
)

'''
setup(
    name        = "game",
    version     = "0.1",
    description = "my game",
    options = {"build_exe": build_exe_options},
    executables = [
        Executable(
            "game.py",
            base = base
        )
    ]
)

'''


EDIT:
If i switched this:
Code: Select all
[code]for i in ['dbhash', 'gdbm', 'dbm', 'dumbdbm']:
    try:
        eval('import '+i)
    except:
        pass[/code]

to this:
Code: Select all
for dbmodule in ['dbhash', 'gdbm', 'dbm', 'dumbdbm']:
    try:
        __import__(dbmodule)
    except ImportError:
        pass
    else:
        # If we found the module, ensure it's copied to the build directory.
        packages.append(dbmodule)

i get this error:
Code: Select all
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "game.py", line 36, in <module>
  File "C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master\data\tools.py", line 26, in load
    db = shelve.open(DB.path)
  File "C:\Python27\lib\shelve.py", line 239, in open
    return DbfilenameShelf(filename, flag, protocol, writeback)
  File "C:\Python27\lib\shelve.py", line 223, in __init__
    Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
  File "C:\Python27\lib\anydbm.py", line 84, in open
    mod = __import__(result)
  File "C:\Python27\lib\dbhash.py", line 7, in <module>
    import bsddb
ImportError: No module named bsddb


If i add bsddb to the import loop, i get this error:
Code: Select all
C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master>python setup.py build

running build
running build_exe
Traceback (most recent call last):
  File "setup.py", line 55, in <module>
    executables = [GUI2Exe_Target_1]
  File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
    distutils.core.setup(**attrs)
  File "C:\Python27\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 232, in run
    freezer.Freeze()
  File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 603, in Freeze

    self.finder = self._GetModuleFinder()
  File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 345, in _GetMo
duleFinder
    finder.IncludePackage(name)
  File "C:\Python27\lib\site-packages\cx_Freeze\finder.py", line 686, in Include
Package
    module = self._ImportModule(name, deferredImports)
  File "C:\Python27\lib\site-packages\cx_Freeze\finder.py", line 386, in _Import
Module
    raise ImportError("No module named %r" % name)
ImportError: No module named 'bsddb'


Code: Select all
C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master>python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
>>> exit()

C:\Users\metul_000\Downloads\FloodIt-master\FloodIt-master>


At this point i feel like i am just running around in circles.

The other suggestions i see is to use another method to save data, but it seems rediculous to avoid using shelve only because cx_freeze doesnt play nice with it.

EDIT:
OK i thought i had this same working in py2exe, but i get the same dbm error with py2exe when using shelve. Has anyone else had this problem?
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2228
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: cx_freeze no dbm clone found

Postby metulburr » Fri May 23, 2014 6:38 pm

I wasnt able to figure out how to fix it, but the method to get around it was I stopped using shelve, and used something else, for me JSON.
Both cxfreeze and py2exe built an exe after switching from shelve to json
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2228
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 8 guests