title: Is there any way to include all of the sound effects for my pygame game into my .exe with pyinstaller?
body: <p>I have made a relatively simple pygame program with 9 different sound effects (<code>.wav</code> format, if this information is important). When converting my <code>main.py</code> to an executable file with the <a href="https://pypi.org/project/pyinstaller/" rel="nofollow noreferrer">pyinstaller</a> module, is there any way I can get the sound effects to be included in the executable, or will I need to find a work-around (such as having the sound effects in the <code>C:\Program Files</code> path)?</p>
  <p>Here's the contents of my <code>.spec</code> file:</p>
  <pre><code># -*- mode: python ; coding: utf-8 -*-
  
  
  block_cipher = None
  
  added_files = [('C:\\Users\\joshu\\CursorHunters\\Assets\\Sounds\\*.wav', 'Sounds')]
  
  a = Analysis(['main.py'],
               pathex=[],
               binaries=[],
               datas=added_files,
               hiddenimports=[],
               hookspath=[],
               hooksconfig={},
               runtime_hooks=[],
               excludes=[],
               win_no_prefer_redirects=False,
               win_private_assemblies=False,
               cipher=block_cipher,
               noarchive=False)
  pyz = PYZ(a.pure, a.zipped_data,
               cipher=block_cipher)
  
  exe = EXE(pyz,
            a.scripts,
            a.binaries,
            a.zipfiles,
            a.datas,  
            [],
            name='Cursor Hunters',
            debug=False,
            bootloader_ignore_signals=False,
            strip=False,
            upx=True,
            upx_exclude=[],
            runtime_tmpdir=None,
            console=False,
            disable_windowed_traceback=False,
            target_arch=None,
            codesign_identity=None,
            entitlements_file=None )
  </code></pre>
  <p>As you can see, the sounds are located in <code>\C:\Users\joshu\CursorHunters\Assets\Sounds</code>, and my <code>main.py</code> is located in <code>\C:\Users\joshu\CursorHunters</code>.</p>
  <p>Instead of packing the <code>.wav</code> files together with the <code>.exe</code> file, it returns this error when ran without the <code>Assets\Sounds</code> folder in the same directory:
  <a href="https://i.stack.imgur.com/JmnPJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JmnPJ.png" alt="Error message when .exe is ran without the Assets\Sounds folder in the same directory." /></a></p>
  <p>This is how I access my <code>.wav</code> files in <strong><code>sound_effects.py</code></strong> followed by <strong><code>main.py</code></strong>:</p>
  <pre><code>import os.path, pygame, sys
  
  pygame.mixer.init()
  
  
  class SoundEffects(object):
  
  
      def __init__(self,
                   EXE_LOCATION: str):
          self.explosion1 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;explosion1.wav&quot;))
          self.explosion2 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;explosion2.wav&quot;))
          self.explosion3 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;explosion3.wav&quot;))
          self.explosion4 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;explosion4.wav&quot;))
          self.explosion5 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;explosion5.wav&quot;))
          self.explosion_sounds = (self.explosion1,
                                   self.explosion2,
                                   self.explosion3,
                                   self.explosion4,
                                   self.explosion5)
          self.gameover1 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;gameover1.wav&quot;))
          self.gameover2 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;gameover2.wav&quot;))
          self.gameover3 = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;gameover3.wav&quot;))
          self.gameover_sounds = (self.gameover1,
                                  self.gameover2,
                                  self.gameover3)
          self.restart_sound = pygame.mixer.Sound(os.path.join(EXE_LOCATION, &quot;Assets&quot;, &quot;Sounds&quot;, &quot;restart.wav&quot;))
  </code></pre>
  <p><strong><code>main.py</code>:</strong></p>
  <pre><code>if getattr(sys, &quot;frozen&quot;, False):  # Gets the directory of this script
      EXE_LOCATION = os.path.dirname(sys.executable)
  
  else:
      EXE_LOCATION = os.path.dirname(os.path.realpath(__file__))
  
  pygame.init()  # Initialises all the pygame contents
  sound_effects = SoundEffects(EXE_LOCATION)  # Sound effects library
  </code></pre>