[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] mixer.music in runtime



OK, so I've tried the exe you built into an installer, and I get the "AttributeError: 'module' object has no attribute 'music'" error (which is a good thing - means the distribution files are consistent)

I also tried making the exe with you setup file, and I get an exe which produces the same "AttributeError: 'module' object has no attribute 'music'" error. Playing around with things a small bit doesn't help me understand things any - importing pygame.mixer_music doesn't throw an error when py2exe'd, and the distribution includes mixer_music.pyd, but even before py2exe'd I can't access anything through pygame.mixer_music meaning the only thing that is different as far as I can tell is pygame.mixer.music doesn't show up...

So it seems to be reproducible with the right scripts, but I'm not sure how to debug it and the behavior of the whole pygame.mixer_music import getting bound as pygame.mixer.music by mixer.c and music.c confuses me cause I don't understand it

... however I tried making a very minimal py2exe script for main.py, and making an exe with that, and the exe works fine. So it seems that finding out what between my minimal setup script and Keith's (or Bo's) causes this problem to start occurring could help pin down what exactly it is about the environment that py2exe creates that breaks pygame's mixer.music importing and/or binding

here is the minimal script that produces a working exe for me (you have to manually copy the audio files tho):
------------------------------------------
from distutils.core import setup
import py2exe
import sys

sys.argv.append("py2exe")

setup(windows=['main.py'],
     options = {'py2exe': {'optimize': 2, 'bundle_files':1} },
     zipfile=None)


On Tue, May 20, 2008 at 5:44 PM, Keith Nemitz <musenik@xxxxxxxxx> wrote:

I've uploaded a minimal app that has the problem.

http://p4.hostingprod.com/@mousechief.com/musicFailSetup.exe


Here's the two relevant files:

------------------------------------- audio py



import pygame,os

musicNames = [];
#soundNames = ["sangria","sonar","drop","badswap","chaching","wall"];
soundNames = [];
soundLib = {};

mixer = music = None;  #Hogari_Hisaaki-Yasuko_Yamano-Beagle.ogg
nextMusic = 0;
musicVolume = 1.0; #0.4;
musicFlag = True;

lastSound = "";
lastSndTime = 0;
loopSound = None;


def InitSounds():
   global mixer, music, musicNames;

   #try:
   import pygame.mixer as pymix
   mixer = pymix;
   import pygame.mixer_music
   music = pymix.music;
   #except (ImportError, pygame.error):
   #    return;

   tp = os.path.join('data','music');
   tl = os.listdir(tp);
   for fname in tl:
       if (fname[-4] == '.'):
           musicNames.append(fname);
   music.set_volume(musicVolume);

   PlayMusic();
   while music.get_busy():
       pass
   pass


def PlayMusic(name, loopCount=1):
   if (not music or not musicFlag): return;
   #check music loop preference if loop: loop = -1;
   loop = loopCount;

   if music.get_busy():
       #we really should fade out nicely and
       #wait for the end music event, for now, CUT
       music.stop();

   fullname = os.path.join('data', 'music', name);
   if (os.access(fullname,os.F_OK)):
       music.load(fullname);
   else:
       fullname = os.path.join('data', 'sounds', name);
       music.load(fullname);
   music.play(loop);
   return;



------------------------------------- setup.py

# A setup script showing how to extend py2exe.
#
# In this case, the py2exe command is subclassed to create an installation
# script for InnoSetup, which can be compiled with the InnoSetup compiler
# to a single file windows installer.
#
# By default, the installer will be created as dist\Output\setup.exe.

from distutils.core import setup
import py2exe
import sys
import shutil

################################################################
# arguments for the setup() call

brigiton = dict(
   script = "main.py",
   dest_base = r"prog\brigiton",
   icon_resources = [(1,"DHSGiT.ico")])

zipfile = r"lib\shardlib"

options = {"py2exe": {"compressed": 0,
                     "optimize": 2}, }

#dataList = []; #glob.glob("data\\*");
#scan data folder for files and append in form "data\file

################################################################
import os

class InnoScript:
   def __init__(self,
                name,
                lib_dir,
                dist_dir,
                windows_exe_files = [],
                lib_files = [],
                data_files = [],
                version = "1.0.2.0"): #another one down below.
       self.lib_dir = lib_dir
       self.dist_dir = dist_dir
       if not self.dist_dir[-1] in "\\/":
           self.dist_dir += "\\"
       self.name = name
       self.version = version
       self.windows_exe_files = [self.chop(p) for p in windows_exe_files]
       self.lib_files = [self.chop(p) for p in lib_files]

   def chop(self, pathname):
       assert pathname.startswith(self.dist_dir)
       return pathname[len(self.dist_dir):]

   def create(self, pathname="dist\\brigiton.iss"):
       self.pathname = pathname
       ofi = self.file = open(pathname, "w")
       print >> ofi, "; WARNING: This script has been created by py2exe. Changes to this script"
       print >> ofi, "; will be overwritten the next time py2exe is run!"
       print >> ofi, r"[Setup]"
       print >> ofi, r"AppName=%s" % self.name
       print >> ofi, r"AppVerName=%s %s" % (self.name, self.version)
       print >> ofi, r"DefaultDirName={pf}\%s" % self.name
       print >> ofi, r"DefaultGroupName=%s" % self.name
       print >> ofi

       print >> ofi, r"[Dirs]"
       print >> ofi, r'Name: "{app}\prog\data"'
       print >> ofi, r'Name: "{app}\prog\data\music"'

       print >> ofi

       print >> ofi, r"[Files]"
       print >> ofi, r'Source: "prog\data\music\*"; DestDir: "{app}\prog\data\music"; Flags:
ignoreversion'


       print >> ofi, r'Source: "prog\msvcr71.dll"; DestDir: "{app}\prog"; Flags: ignoreversion'
       #print >> ofi, r'Source: "prog\libpng12-0.dll"; DestDir: "{app}\prog"; Flags:
ignoreversion'
       #print >> ofi, r'Source: "prog\jpeg.dll"; DestDir: "{app}\prog"; Flags: ignoreversion'
       #print >> ofi, r'Source: "prog\libvorbisfile-3.dll"; DestDir: "{app}\prog"; Flags:
ignoreversion'
       #print >> ofi, r'Source: "prog\libogg-0.dll"; DestDir: "{app}\prog"; Flags: ignoreversion'
       #print >> ofi, r'Source: "prog\libvorbis-0.dll"; DestDir: "{app}\prog"; Flags:
ignoreversion'
       print >> ofi, r'Source: "prog\libfreetype-6.dll"; DestDir: "{app}\lib"; Flags:
ignoreversion'
       #print >> ofi, r'Source: "prog\zlib1.dll"; DestDir: "{app}\lib"; Flags: ignoreversion'


       for path in self.windows_exe_files + self.lib_files:
           print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' % (path,
os.path.dirname(path))
       print >> ofi

       print >> ofi, r"[Icons]"
       for path in self.windows_exe_files:
           print >> ofi, r'Name: "{group}\%s"; Filename: "{app}\%s"' % \
                 (self.name, path)
       print >> ofi, 'Name: "{group}\Uninstall %s"; Filename: "{uninstallexe}"' % self.name

   def compile(self):
       try:
           import ctypes
       except ImportError:
           try:
               import win32api
           except ImportError:
               import os
               os.startfile(self.pathname)
           else:
               print "Ok, using win32api."
               win32api.ShellExecute(0, "compile",
                                               self.pathname,
                                               None,
                                               None,
                                               0)
       else:
           print "Cool, you have ctypes installed."
           res = ctypes.windll.shell32.ShellExecuteA(0, "compile",
                                                     self.pathname,
                                                     None,
                                                     None,
                                                     0)
           if res < 32:
               raise RuntimeError, "ShellExecute failed, error %d" % res


################################################################

from py2exe.build_exe import py2exe

class build_installer(py2exe):
   # This class first builds the exe file(s), then creates a Windows installer.
   # You need InnoSetup for it.
   def run(self):
       # First, let py2exe do it's work.
       py2exe.run(self)

       lib_dir = self.lib_dir
       dist_dir = self.dist_dir

       # create the Installer, using the files py2exe has created.
       script = InnoScript("DangerousHSGirls",
                           lib_dir,
                           dist_dir,
                           self.windows_exe_files,
                           self.lib_files)
       print "*** creating the inno setup script***"
       script.create()
       print "*** compiling the inno setup script***"
       script.compile()
       # Note: By default the final setup.exe will be in an Output subdirectory.

################################################################

setup(
   options = options,
   version = "1.0.2.0", #last digit for Windows increments between Mac increments
   description = "py2exe script",
   name = "Dangerous HS Girls in Trouble!",

   # The lib directory contains everything except the executables and the python dll.
   zipfile = zipfile,
   windows = [brigiton],
   # use out build_installer class as extended py2exe build command
   cmdclass = {"py2exe": build_installer},
   #data_files = [("prog\data", [])],
   )






--- Keith Nemitz <musenik@xxxxxxxxx> wrote:

>
> I've started with fresh XP Sp2 installs on both VMWare and Parallels. Installed only what was
> necessary:
>
> Python, pygame, numeric, py2exe.
>
> As per earlier suggestion, I uninstalled py2exe 0.6.6 and installed 0.6.5.
>
> I don't think it's an install issue.
>
>
>
>
> --- René Dudfield <renesd@xxxxxxxxx> wrote:
>
> > ah,
> >
> > Have you tried uninstalling (maybe manually deleting) pygame, py2exe
> > etc then installing again?
> >
> > Maybe there's some problem with that...
> >
> >
> >
> > On Wed, May 21, 2008 at 9:31 AM, Keith Nemitz <musenik@xxxxxxxxx> wrote:
> > > Yep,
> > >
> > > It's in Program Files/(AppFolder)/lib.
> > >
> > >
> > >
> > >
> > > --- René Dudfield <renesd@xxxxxxxxx> wrote:
> > >
> > >> hi,
> > >>
> > >> Do you have the smpeg dll copied in there?
> > >>
> > >> cu,
> > >>
> > >>
> > >> On Wed, May 21, 2008 at 7:58 AM, Keith Nemitz <musenik@xxxxxxxxx> wrote:
> > >> > I get the following:
> > >> >
> > >> > AttributeError: 'module' object has no attribute 'mixer_music'
> > >> >
> > >> >
> > >> >
> > >> >
> > >> > --- Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
> > >> >
> > >> >> I guess that means it imports correctly, but somehow fails to get bound?
> > >> >>
> > >> >> I don't suppose you can access the functionality you need through
> > >> >> mixer_music, can you?
> > >> >>
> > >> >> In other words, what happens if you change the first failing
> > >> >> pygame.mixer.music.whatever line to pygame.mixer_music.whatever? (after the
> > >> >> import, of course)
> > >> >>
> > >> >> On Tue, May 20, 2008 at 11:17 AM, Keith Nemitz <musenik@xxxxxxxxx> wrote:
> > >> >>
> > >> >> > I put your import line right above the failing line, but got exactly the
> > >> >> > same results. I even
> > >> >> > removed the try/exception block.
> > >> >> >
> > >> >> >
> > >> >>
> > >> >
> > >> >
> > >>
> > >
> > >
> >
>
>