title: Error after creating executable Pygame with Pyinstaller
body: <p>So my pygame script in python works perfectly, so I decided to try to bundle the program in order to distribute it, using <a href="https://pyinstaller.readthedocs.io/en/stable/usage.html" rel="nofollow noreferrer">Pyinstaller</a>. I compiled and ran Pyinstaller just as directed:</p>
  
  <pre><code>sudo pip install pyinstaller
  pyinstaller Loop.py
  </code></pre>
  
  <p>It worked fine. Then I ran the generated executable file to see it in action: </p>
  
  <pre><code>cd /dist/Loop/
  ./Loop
  </code></pre>
  
  <p>The result, was this:</p>
  
  <pre><code>Fatal Python error: (pygame parachute) Segmentation Fault
  Aborted (core dumped)
  </code></pre>
  
  <p>Not a single line of Loop.py seems to be executed, since the first lines after importing packages is to open a new window (which didn't happen). With a little googling, it seems the only recommended solution is to debug the code to find where the segmentation took place. However, that doesn't make sense since the code works perfectly fine on its own, it only does this after using pyinstaller. I even entered a python shell in the same directory as the Loop executable, and verified that there is no problem in importing pygame. </p>
  
  <p>At any rate, I'm just looking for a way to bundle the python project. Of course, if you know any better way to bundle a python project for distribution (using Python 2.7 on Ubuntu 16) I'd be happy to check it out :)</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I created a version of my code which is as simplified as possible, in order to focus on the main issue (and of course to prove that the problem is reproducible). Here is the main program (<code>Loop.py</code>):</p>
  
  <pre><code>from Car import*
  
  vehicle = Car()
  
  
  def display_all(main_surface, display_list):
      main_surface.fill((0, 100, 100))
      for element in display_list:
          element.display(main_surface)
  
  
  def update_all(update_list):
      for element in update_list:
          element.update()
  
  
  running = True
  while running:
      clock.tick(60)
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              running = False
  
          if event.type == pygame.KEYDOWN:
              None
  
      key = pygame.key.get_pressed()
  
      to_update = [vehicle]
      to_display = [vehicle]
  
      update_all(to_update)
      display_all(main_s, to_display)
      pygame.display.flip()
  </code></pre>
  
  <p>And here is <code>Car.py</code>:</p>
  
  <pre><code>from Startup import*
  
  
  class Car:
      def __init__(self):
          self.body = pygame.image.load("Images//Body//Grey.png")
          self.wheels = pygame.image.load("Images//Wheels//Black.png")
          self.rect = self.body.get_rect()
          self.rect.x = width/2
          self.rect.y = height/2
          self.rect.center = self.rect.x, self.rect.y
          self.angle = 0
          self.move_x = 0
          self.move_y = 0
  
      def display(self, main_surface):
          temp_image = pygame.transform.rotate(self.body, self.angle)
          main_surface.blit(temp_image, (self.rect.x, self.rect.y))
          temp_image = pygame.transform.rotate(self.wheels, self.angle)
          main_surface.blit(temp_image, (self.rect.x, self.rect.y))
  
      def update(self):
          self.move_x = 0
          self.move_y = 0
  </code></pre>
  
  <p>And here is <code>Startup.py</code>:</p>
  
  <pre><code>import pygame
  import math
  pygame.font.init()
  
  clock = pygame.time.Clock()
  font = pygame.font.SysFont("", 20)
  
  pygame.init()
  width = 1000
  height = 600
  main_s = pygame.display.set_mode((width, height))
  </code></pre>
  
  <p><strong>Edit (again)</strong></p>
  
  <p>I just tried <code>py2app</code> as suggested in the comment, and it doesn't seem to work. As seen in <a href="https://py2app.readthedocs.io/en/latest/#" rel="nofollow noreferrer">the only documentation</a> I can find, the intention is to be run on MacOS. As clearly stated above, I am using Ubuntu 16, and that is the architecture I am coding on. When I completed the tutorial linked above, I had no complications, and proceeded to execute the file:</p>
  
  <pre><code>./dist/Loop.app/Contents/MacOS/Loop
  </code></pre>
  
  <p>And I promptly got the error:</p>
  
  <pre><code>bash: cannot execute binary file: Exec format error
  </code></pre>
  
  <p>This seems to indicate it is not meant for my computer. </p>
  
  <p>Do you have any idea if there is a version that works for Ubuntu? or if there is another solution?</p>
  
  <p>Thanks,
  Nathan</p>