title: Package python file with imgs and modules to an executable file?
body: <p>Can someone please either help me by doing it, or carefully explain to me how to do the following:</p>
  <p>I want the python program provided below (<em>memory.py</em>, a free-to-use memory game with a background image which I copied from <a href="http://www.grantjenks.com/docs/freegames/memory.html" rel="nofollow noreferrer">This Link</a>.) to run with a different background image than the default one. Here's my image:
  <a href="https://i.stack.imgur.com/CAcUD.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CAcUD.gif" alt="aston.gif" /></a></p>
  <p><em>aston.gif</em></p>
  <p>And I want it all (there are some modules imported in the program) packaged into one executable file. I want to be able to share it with someone who neither has python installed on their computer, nor knows how to use a terminal. (I don't even know if it's an exe file I need. If there is a better way of achieving the same thing, I'm all for it!)</p>
  <p>I have watched and tried to follow along a million tutorials, from google, books and on youtube. Mostly by using pyinstaller and auto-py-to-exe in different ways, but nothing works for me.</p>
  <p>I used pip to install freegames successfully, and I found the default image located in:</p>
  <p><em>My_MacBook/MacintoshHD/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/freegames</em></p>
  <p>I have also converted my image to the same size (400x400) and to the same extension (gif) as the default image. When I put my image in the path end above (and of course exchange the name of the image in the program), and run it from my terminal, everything works just fine.</p>
  <p>But I don't know where to put my image when packaging it all together, nor do I understand how to include the modules. Especially the 'freegames' one puzzles me. I tried to put all the py-files (program and modules) in the same dir, and then used different ways of packaging them together, but I can't make it work, even when I try it with the default image.</p>
  <p>For example:</p>
  <ol>
  <li>I installed freegames with pip, successfully.</li>
  <li>I then removed the default gif-img from /freegames and replaced it with my own image (same format and size).</li>
  <li>I changed 'default.gif' to my_img.gif' in memory.py.</li>
  <li>I ran $ 'python3 memory.py' in my terminal, successfully. A new window appeared and the game worked just as it should, revealing the correct image in the background (my img).</li>
  <li>I installed pyinstaller, successfully.</li>
  <li>I ran the command $ 'pyinstaller --onefile --windowed memory.py'</li>
  <li>It looked like it ran properly, and I got the corresponding folders (build, dist) back. But neither the memory.exe nor the memory.app worked, it just appeared a black window.</li>
  <li>Inside build there was a file called 'warn_memory.txt' that said that pyinstaller was unable to find some of my listed modules (all though I read the pyinstallet documentation, where it explicitly says that the pyinstaller will find the modules by itself, they do not need to be included as copies in the same folder as the program).</li>
  </ol>
  <p>Here is the warning file:</p>
  <p><em>warn_memory.txt</em></p>
  <hr />
  <pre><code>This file lists modules PyInstaller was not able to find. This does not
  necessarily mean this module is required for running you program. Python and
  Python 3rd-party packages include a lot of conditional or optional modules. For
  example the module 'ntpath' only exists on Windows, whereas the module
  'posixpath' only exists on Posix systems.
  
  Types if import:
  * top-level: imported at the top-level - look at these first
  * conditional: imported within an if-statement
  * delayed: imported from within a function
  * optional: imported within a try-except-statement
  
  IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
             yourself tracking down the missing module. Thanks!
  
  missing module named _winapi - imported by encodings (delayed, conditional, optional), subprocess (optional), test.support (delayed, conditional), multiprocessing.connection (optional), multiprocessing.spawn (delayed, conditional), multiprocessing.reduction (conditional), multiprocessing.shared_memory (conditional), multiprocessing.heap (conditional), multiprocessing.popen_spawn_win32 (top-level), asyncio.windows_events (top-level), asyncio.windows_utils (top-level)
  missing module named msvcrt - imported by subprocess (optional), getpass (optional), test.support (delayed, conditional, optional), multiprocessing.spawn (delayed, conditional), multiprocessing.popen_spawn_win32 (top-level), asyncio.windows_events (top-level), asyncio.windows_utils (top-level)
  missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional), zipimport (top-level)
  excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional), zipimport (top-level)
  missing module named pep517 - imported by importlib.metadata (delayed)
  missing module named winreg - imported by importlib._bootstrap_external (conditional), platform (delayed, optional), mimetypes (optional), urllib.request (delayed, conditional, optional)
  missing module named org - imported by copy (optional)
  missing module named nt - imported by os (delayed, conditional, optional), ntpath (optional), shutil (conditional), importlib._bootstrap_external (conditional), pathlib (conditional), ctypes (delayed, conditional)
  missing module named 'org.python' - imported by pickle (optional), xml.sax (delayed, conditional)
  missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
  missing module named multiprocessing.BufferTooShort - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
  missing module named multiprocessing.AuthenticationError - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
  missing module named _overlapped - imported by asyncio.windows_events (top-level)
  missing module named asyncio.DefaultEventLoopPolicy - imported by asyncio (delayed, conditional), asyncio.events (delayed, conditional)
  missing module named vms_lib - imported by platform (delayed, optional)
  missing module named java - imported by platform (delayed)
  missing module named _winreg - imported by platform (delayed, optional)
  missing module named multiprocessing.get_context - imported by multiprocessing (top-level), multiprocessing.pool (top-level), multiprocessing.managers (top-level), multiprocessing.sharedctypes (top-level)
  missing module named multiprocessing.TimeoutError - imported by multiprocessing (top-level), multiprocessing.pool (top-level)
  missing module named multiprocessing.set_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
  missing module named multiprocessing.get_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
  </code></pre>
  <hr />
  <p>Here is the code:</p>
  <p><em>memory.py</em></p>
  <hr />
  <pre><code>from random import *
  from turtle import *
  from freegames import path
  
  car = path('car.gif')
  tiles = list(range(32)) * 2
  state = {'mark': None}
  hide = [True] * 64
  
  def square(x, y):
      &quot;Draw white square with black outline at (x, y).&quot;
      up()
      goto(x, y)
      down()
      color('black', 'white')
      begin_fill()
      for count in range(4):
          forward(50)
          left(90)
      end_fill()
  
  def index(x, y):
      &quot;Convert (x, y) coordinates to tiles index.&quot;
      return int((x + 200) // 50 + ((y + 200) // 50) * 8)
  
  def xy(count):
      &quot;Convert tiles count to (x, y) coordinates.&quot;
      return (count % 8) * 50 - 200, (count // 8) * 50 - 200
  
  def tap(x, y):
      &quot;Update mark and hidden tiles based on tap.&quot;
      spot = index(x, y)
      mark = state['mark']
  
      if mark is None or mark == spot or tiles[mark] != tiles[spot]:
          state['mark'] = spot
      else:
          hide[spot] = False
          hide[mark] = False
          state['mark'] = None
  
  def draw():
      &quot;Draw image and tiles.&quot;
      clear()
      goto(0, 0)
      shape(car)
      stamp()
  
      for count in range(64):
          if hide[count]:
              x, y = xy(count)
              square(x, y)
  
      mark = state['mark']
  
      if mark is not None and hide[mark]:
          x, y = xy(mark)
          up()
          goto(x + 2, y)
          color('black')
          write(tiles[mark], font=('Arial', 30, 'normal'))
  
      update()
      ontimer(draw, 100)
  
  shuffle(tiles)
  setup(420, 420, 370, 0)
  addshape(car)
  hideturtle()
  tracer(False)
  onscreenclick(tap)
  draw()
  done()
  </code></pre>
  <hr />
  <p>To summarize:</p>
  <ol>
  <li><p>How does one package a Python project along with its pip dependencies (such as freegames) to one single executable?</p>
  </li>
  <li><p>How does one set an alternative background image for the memory game that's provided by freegames in such a way that it still works when the whole thing is packaged as an executable?</p>
  </li>
  </ol>
  <p>I should say that I have just started learning Python, so this is of course waaay beyond my level. I just really want a memory game with my parents dog in it :p.
  And I'm using a MacBook Pro, if that matters.</p>
  <p>Thank you in advance!</p>
  <p>Update:</p>
  <ul>
  <li>I tried to rewrite a small part of the code so that the freegames module was no longer neccessary (at least I thought so...).</li>
  <li>I removed the import statement at the top of the file (still importing random and turtle though).</li>
  <li>I then put my image in the same folder as memory.py and referred to it in the program as a relative path, simply 'aston.gif'.</li>
  <li>It worked in the terminal, like before. Correct output and img.</li>
  <li>But same issue as before when I tried to made an exe out of it with pyinstaller. Pyinstaller cannot find imported modules -- just a black window.</li>
  </ul>