Making .app and .exe files from .py scripts

A forum for general discussion of the Python programming language.

Making .app and .exe files from .py scripts

Postby agentsmith » Sun Jan 26, 2014 12:21 pm

Is there any real way to make .app and .exe files from even the simplest .py scripts and games written in Python 3?

py2exe only supports python 2.x, as far as I can understand.

In the last few days I have used cx_freeze for .exe files, but ended up with various error messages, even for very simple scripts.
I also tried to get PyInstaller but discovered that Python 3 is not supported (yet).

I have also tried py2app for .app files but ended up with a bunch of error messages.

I won't bother you with any and all the error messages that I am getting. This said, if you please, if is there a good practical chance with Python 3, please put me in the right direction, and I'll follow it.... thank you.
agentsmith
 
Posts: 13
Joined: Sun Jan 05, 2014 10:51 am

Re: Making .app and .exe files from .py scripts

Postby Mekire » Sun Jan 26, 2014 1:44 pm

Is there any major thing preventing you from converting your code to 2.x. I would say that was the easiest route honestly.

Cxfreeze should work with python3 though. I would need more information to know why this isn't working.

Do you have a link to your code?

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Making .app and .exe files from .py scripts

Postby metulburr » Sun Jan 26, 2014 1:57 pm

i seriously tried this method for the past couple of years. Between having linux compatability, python3.x, etc. it really is just a pain in the *ss. and the end results being it is much easier to convert your code to 2.x. Its not too much work with the latest minor releases of 2.7.X, you just have to make sure to try/except python2.x/python3/x libraries. With some monior manipulation, you can easily get your code to run in both 2.x and 3.x and then just compile the exe using python2.x
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Making .app and .exe files from .py scripts

Postby agentsmith » Sun Jan 26, 2014 2:30 pm

Thank you both. One problem is that I am a beginner and it's not easy for me to convert any Python 3.x into 2.x... anyway, I guess we are getting into details very soon, so perhaps this thread should be moved to the appropriate location. OK let's start with a very simple case: I am using Windows 7 64 bit and Python 3.3. If I write the simplest of command-line scripts, e.g:

test.py

Code: Select all
name = input ("what's your name? ")
print ("hello, ",name)


And then, using cxfreeze, in the Python33\Scripts directory:, where the script is saved, I go this way. (I have seen it going well in the following youtube tutorial, but sadly it does not work for me.)

http://www.youtube.com/watch?v=XHcDHSWRCRQ

C:\Python33\Scripts>cxfreeze-quickstart
Project name: Test
Version [1.0]: 1.0
Description: a test of mine
Python file to make executable from: test.py
Executable file name [test]:
(C)onsole application, (G)UI application, or (S)ervice [C]: C
Save setup script to [setup.py]:
Overwrite setup.py [n]? y

Setup script written to setup.py; run it as:
python setup.py build
Run this now [n]? y
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 17, in <module>
executables = executables)
File "C:\Python33\lib\site-packages\cx_Freeze\dist.py", line 365, in setup
distutils.core.setup(**attrs)
File "C:\Python33\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python33\lib\distutils\dist.py", line 929, in run_commands
self.run_command(cmd)
File "C:\Python33\lib\distutils\dist.py", line 948, in run_command
cmd_obj.run()
File "C:\Python33\lib\distutils\command\build.py", line 126, in run
self.run_command(cmd_name)
File "C:\Python33\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python33\lib\distutils\dist.py", line 948, in run_command
cmd_obj.run()
File "C:\Python33\lib\site-packages\cx_Freeze\dist.py", line 234, in run
metadata = metadata)
File "C:\Python33\lib\site-packages\cx_Freeze\freezer.py", line 101, in __init
__
for n in self._GetDefaultBinPathExcludes() + binPathExcludes]
File "C:\Python33\lib\site-packages\cx_Freeze\freezer.py", line 235, in _GetDe
faultBinPathExcludes
import cx_Freeze.util
ImportError: DLL load failed: %1 is not a valid win32 application

Am I missing anything?
agentsmith
 
Posts: 13
Joined: Sun Jan 05, 2014 10:51 am

Re: Making .app and .exe files from .py scripts

Postby metulburr » Sun Jan 26, 2014 2:37 pm

It looks like you have a mismatch of 32/64 bits apps.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Making .app and .exe files from .py scripts

Postby agentsmith » Sun Jan 26, 2014 2:47 pm

I downloaded cxfreeze for Python 3.3 at 64 bit...
agentsmith
 
Posts: 13
Joined: Sun Jan 05, 2014 10:51 am

Re: Making .app and .exe files from .py scripts

Postby agentsmith » Sun Jan 26, 2014 3:47 pm

I did some little progress, I just downloaded Python 3.3 at 64 bits for AMD etc. and the little test script succesfully builds to a .EXE file. The problem now is with a little game that I just wrote using Pygame.
agentsmith
 
Posts: 13
Joined: Sun Jan 05, 2014 10:51 am

Re: Making .app and .exe files from .py scripts

Postby agentsmith » Sun Jan 26, 2014 4:28 pm

Well, I did some little further progress, I just downloaded the "unofficial" 64-bits version of Pygame from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
The only error message that I am getting at this point - let's hope so - is "unable to find intro.ogg". All the .ogg sounds are in the right directory, any hint or suggestion? I will paste the game code if needed.
agentsmith
 
Posts: 13
Joined: Sun Jan 05, 2014 10:51 am

Re: Making .app and .exe files from .py scripts

Postby metulburr » Sun Jan 26, 2014 8:13 pm

The only error message that I am getting at this point - let's hope so - is "unable to find intro.ogg". All the .ogg sounds are in the right directory, any hint or suggestion? I will paste the game code if needed.

Please read New Users, Read This link to see what is required in a full post. We need the full traceback and the code that gave it. Your comment here, is way too little to figure out the reason why it won't load.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Making .app and .exe files from .py scripts

Postby agentsmith » Sun Jan 26, 2014 8:27 pm

I did not put any actual code sample here or any details because my original question was intended just as a general suggestion or advice on what to use for creating .exe and .app files from .py files... this said, at this point a problem seems to be with sound files. I did a very simple pong game and here is the code:
Code: Select all
import pygame, time, random, sys



black = (0, 0, 0)
white = (255, 255, 255)
green = (0, 255, 0)
red =   (255, 0, 0)



pygame.init()

size = [700, 500]

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Pong")


def gameOverWon():

    done = True

    screen.fill(black)
    font = pygame.font.SysFont("arial", 35)
    text = font.render ("Game over.",True, red)
    text1 = font.render ("You WON!",True, red)
    text2 = font.render ("Play again? (Y/N)",True, red)

    screen.blit(text,  [200, 50])
    screen.blit(text1,  [200, 100])
    screen.blit(text2,  [200, 150])

    while done == True:
   
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
             

            elif event.type == pygame.KEYDOWN:
              if event.key == pygame.K_y:
                 
                  intro()

              elif event.key == pygame.K_n:
                  pygame.quit()
                  sys.exit()

     
       

       
        clock=pygame.time.Clock()   
        pygame.display.flip()
        clock.tick(20)
   
   
   

def gameOverLost():
    done = True

    screen.fill(black)
    font = pygame.font.SysFont("arial", 35)
    text = font.render ("Game over.",True, red)
    text1 = font.render ("You LOST!",True, red)
    text2 = font.render ("Play again? (Y/N)",True, red)

    screen.blit(text,  [200, 50])
    screen.blit(text1,  [200, 100])
    screen.blit(text2,  [200, 150])

    while done == True:
   
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
             

            elif event.type == pygame.KEYDOWN:
              if event.key == pygame.K_y:
                 
                  intro()

              elif event.key == pygame.K_n:
                  pygame.quit()
                  sys.exit()

     
       

       
        clock=pygame.time.Clock()   
        pygame.display.flip()
        clock.tick(20)

   







def intro():

    done = False

    sound4 = pygame.mixer.Sound("intro.ogg")
    sound4.play()

   
   
    while done == False:
        for event in pygame.event.get():
          if event.type == pygame.QUIT:
            done = True
            sys.exit()

          elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RETURN:
                play()


        screen.fill(black)
        font = pygame.font.SysFont("arial", 25)

        text = font.render ("Welcome to Pong game.",True, red)
        text1 = font.render("After 10 points, a set is won.",True, red)
        text2 = font.render("After 2 sets, the game is won (or lost).",True, red)
        text3 = font.render("Press ENTER to play.", True, red)

        screen.blit(text,  [200, 50])
        screen.blit(text1, [200,80])
        screen.blit(text2, [200,110])
        screen.blit(text3, [200,140])

       



        clock=pygame.time.Clock()   

           

        pygame.display.flip()



        clock.tick(20)

def play():

    black = (0, 0, 0)
    white = (255, 255, 255)
    yellow = (255, 255, 0)
    red =   (255, 0, 0)
    green = (0, 128, 0)

    pygame.init()

    size = [700, 500]

    screen = pygame.display.set_mode(size)

    pygame.display.set_caption("Pong")

    done = False

    sound  = pygame.mixer.Sound("Pong.ogg")
    sound1 = pygame.mixer.Sound("Ping.ogg")
    sound2 = pygame.mixer.Sound("Powerup.ogg")
    sound3 = pygame.mixer.Sound("Lost.ogg")


    clock=pygame.time.Clock()



    rect_x = random.randrange(690)
    rect_y = 15

    you = 0
    computer = 0
    setyou = 0
    setcomputer = 0

    x_pos = 10
    x_speed = 0

    rect_change_x = 6
    rect_change_y = 6

    font = pygame.font.SysFont("arial",25)




    while done == False:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          done = True
          sys.exit()

        elif event.type == pygame.KEYDOWN:
          if event.key == pygame.K_LEFT:
              x_speed = -6

          elif event.key == pygame.K_RIGHT:
              x_speed = 6

         
           

        elif event.type == pygame.KEYUP:
          if event.key == pygame.K_LEFT:
            x_speed = 0

          elif event.key == pygame.K_RIGHT:
            x_speed = 0

      x_pos += x_speed



      screen.fill(black)

      pygame.draw.rect(screen, yellow, [rect_x, rect_y, 15, 15])

      rect_x += rect_change_x
      rect_y += rect_change_y

      if rect_y == 465 and rect_x >= x_pos and rect_x <= x_pos +40:
        rect_change_y = rect_change_y * -1
        you += 1
        sound.play()

     
      #if rect_y >=300:
       
     #  rect_change_y = 7
     #  rect_change_x = 7

      elif rect_y >=480:
       
        computer += 1
        sound3.play()
       
        rect_x = random.randrange(690)
        rect_y = 15
       
       

      elif rect_y < 0:
        rect_change_y = rect_change_y * -1
        sound1.play()

     

      if rect_x > 685 or rect_x < 0:
        rect_change_x = rect_change_x * -1
        sound1.play()


       

      if you == 10:
        setyou += 1
        you = 0
        computer = 0
        time.sleep(0.1)
        sound2.play()

      elif computer == 10:
        setcomputer += 1
        you = 0
        computer = 0
        time.sleep(0.1)
        sound2.play()

      if setcomputer == 2:
          done = True
          gameOverLost()

      elif setyou == 2:
          done = True
          gameOverWon()
     
       


      pygame.draw.rect(screen, white, [x_pos, 480, 40, 10])


      text = font.render("Pong", True, red)
      screen.blit(text, [10,10])

      text1 = font.render("You: 0" +str(you), True, white)
      screen.blit(text1, [620,10])

      text2 = font.render("Score - Computer: 0" +str(computer), True, white)
      screen.blit(text2, [420,10])

      text3 = font.render("Sets - Computer: 0" +str(setcomputer),  True, green)
      screen.blit(text3, [100,10])

      text3 = font.render("You: 0" +str(setyou),  True, green)
      screen.blit(text3, [290,10])

     
       
       
     

         

      pygame.display.flip()



      clock.tick(30)


intro()

pygame.quit()







agentsmith
 
Posts: 13
Joined: Sun Jan 05, 2014 10:51 am

Re: Making .app and .exe files from .py scripts

Postby metulburr » Sun Jan 26, 2014 8:39 pm

Yeah but if your going to ask a second question, then all the rules apply still with the second question, especially since it has nothing to do with the initial question. Actually now thinking about it, it should be a seperate thread altogether. This question is about loading resources, the initial question is about creating exes, completely different.

supply the intro.ogg file on mediafire, github, or someplace for us to grab it.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1469
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests