title: Pyinstaller image does not load
body: <p><strong>The Problem</strong></p>
  
  <p>Im trying to turn a python file into an EXE file, however I seem to be running into the same problem every single time, whether it is CX_Freeze or Pyinstaller. I just tried using pyinstaller and I made an EXE file using the command</p>
  
  <pre><code>pyinstaller --onefile thepyfile
  </code></pre>
  
  <p>and everything works fine. It creates the exe in the dist file. However when I open the exe it shows me a command window and then quickly turns off. I managed to capture the error im getting using print screen, and it said
  pygame error: Couldn't open image family.jpg. I am using the pygame module. </p>
  
  <p><strong>What have I tried?</strong></p>
  
  <p>Iv made sure that the images are in the same directory and the same folder as my python file. My .py works fine when I run it, it's just the exe. Anyways just to make sure that there's no problems loading the images in the path I joined the path using </p>
  
  <pre><code>os.path.join
  </code></pre>
  
  <p>Again it worked for the py file, but it did not work in the exe. I have also checked if I installed pyinstaller correctly, and it works for other exe programs that don't involve importing images. I also did try to create a folder and then use</p>
  
  <pre><code>os.path.join(folder,file)
  </code></pre>
  
  <p>but again it worked in the py file, but not the pyinstaller/cx_freeze exe. </p>
  
  <p><strong>A clue?</strong></p>
  
  <p>While I was working with CX__freeze I discovered pygame cant import the image either. However it gave me a larger error case, not sure if it's usefull but, it may be a clue? </p>
  
  <p><a href="https://i.stack.imgur.com/asRBH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/asRBH.png" alt="enter image description here"></a></p>
  
  <p><strong>Please Help</strong></p>
  
  <p>Iv been running into this problem for more than 5 weeks now and am desperate for help. </p>
  
  <p><strong>Some Code</strong></p>
  
  <p>This is how I import the image (again works in the py file but not the exe)</p>
  
  <pre><code>family_image = pygame.image.load(os.path.join('folder',"family.jpg")).convert()
  </code></pre>
  
  <p>And if needed heres my cx_Freeze setup.py which also makes the exe file yet gives me image cant be loaded error. </p>
  
  <pre><code>import cx_Freeze
  import sys
  import pygame
  import random
  import math
  import os
  os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python35\\tcl\\tc18.6"
  os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python35\\tcl\\tk8.6"
  
  
  base = None
  
  if sys.platform == 'win32':
      base = "Win32GUI"
  
  
  
  
  
  executables = [cx_Freeze.Executable("Treg&amp;Shelly.py",shortcutName="Cards",shortcutDir="DesktopFolder",base = base)]
  
  cx_Freeze.setup(
      name = "HAPPY NEW YEARS",
      options = {"build_exe":{"packages":["pygame","random","math"],"excludes" : ['tcl','ttk','tkinter','Tkinter'],"include_files":["family.jpg","newyears.png"]}},
      version = "0.01",
      description = "New Years Card",
      executables = executables
  
      )
  </code></pre>
  
  <p><strong>Note</strong></p>
  
  <p>All my images are in a separate folder but are accessible by my python file.  </p>
  
  <p>Also Im using python 3.5</p>
  
  <p>Thank you for any response </p>