Foros del Web » Programando para Internet » Python »

Convertir .py en .exe en Python

Estas en el tema de Convertir .py en .exe en Python en el foro de Python en Foros del Web. Hola a todos/as He terminado un juego en Python y ahora quiero convertirlo en .exe para correrlo en otros SS.OO (Windows, Linux, Mac...) Utilice py2exe ...
  #1 (permalink)  
Antiguo 01/08/2013, 12:35
Enjavado
Invitado
 
Mensajes: n/a
Puntos:
Convertir .py en .exe en Python

Hola a todos/as

He terminado un juego en Python y ahora quiero convertirlo en .exe para correrlo en otros SS.OO (Windows, Linux, Mac...)

Utilice py2exe y realice todo el proceso que hay que hacer hasta crear la carpeta dist, pero cuando abro la carpeta y ejecuto el .exe, me sale un flash rapidísimo con una pantalla negra.

Lo que he utilizado
python 2.3 (Programa de Python)
pythong (IDE donde cree el juego)
py2exe (Convertidor a exe)

Alguien que sepa, me podría decir cual es el motivo por el cual no se me ejecuta el .exe

Ahh: y ya utilice el raw_input al final de las lineas del programa y no se ejecuta tampoco.

Un saludo y agradezco la ayuda
  #2 (permalink)  
Antiguo 01/08/2013, 12:57
 
Fecha de Ingreso: julio-2011
Mensajes: 62
Antigüedad: 12 años, 7 meses
Puntos: 0
Respuesta: Convertir .py en .exe en Python

py2exe solo es para Windows, deberias mostrar el código.
  #3 (permalink)  
Antiguo 01/08/2013, 13:09
Enjavado
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

Me han comentado que este es mejor.

El código no lo tengo ahora aquí, ya se los pasaré esta semana


pero creo que la primera linea la tengo así:

import pythong*

Bueno cuando tenga el código lo paso, un saludo.
  #4 (permalink)  
Antiguo 01/08/2013, 13:11
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años
Puntos: 1360
Respuesta: Convertir .py en .exe en Python

Puedes usar gui2exe.
  #5 (permalink)  
Antiguo 01/08/2013, 13:14
Enjavado
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

Me han comentado que este es mejor(cxfreeze).

El código no lo tengo ahora aquí, ya se los pasaré esta semana


pero creo que la primera linea la tengo así:

import pythong*

Bueno cuando tenga el código lo paso, un saludo.
  #6 (permalink)  
Antiguo 01/08/2013, 21:35
ger84
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

¿te referís a éste pythong? : http://www3.uji.es/~dllorens/PythonG/
  #7 (permalink)  
Antiguo 05/08/2013, 10:01
Enjavado
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

Hola chicos/as:

He utilizado cx_Freeze, parecido a py2exe

Me crea el .exe con windows en una carpeta llamada build

pero cuando abro el ejecutable desde la consola me lanza este fallo:

File "C:\Python26\Lib\site-packages\cx_Freeze\initscripts\Console.py" , line 27
, in <module>
exec code in m.__dict__

File "menu_libro_blanco.py", line 9, in <module>
File "C:\Python26\modulepythong.py", line 844, in <module>
f=open(filename, "r")
IOError: [Errno 2] No such file or directory: "C:\\Python26\\build\\exe.win32-2.6
\\menu_libro_blanco"

Te facilito los 2 archivos el juego y el setup.py

JUEGO (menu_libro_blanco)

Código:
# MENU JUEGO
# ==========

# Importamos libreria de tiempo
import time 
# Importamos todas las funciones del modulo (modulepythong)
from modulepythong import *
# Importamos todo el modulo random
import random

window_coordinates(0, 0, 400, 400) # GENERAMOS RESOLUCION
window_style("The Spaceship Game","black","TODO") # FONDO DE COLOR BLANCO

#-----------------------------------------------------------------------#

create_text(200,350,"The Spaceship Game",13.5,"CENTER","blue")
create_text(200,300,"_Easy level (E)",10,"CENTER")
create_text(200,250,"_Medium level (M)",10,"CENTER")
create_text(200,200,"_Hard level (H)",10,"CENTER")
create_text(200,150,"_Exit(X)",10,"CENTER")
  
#-----------------------NIVELES DE JUEGO--------------------------#
a = str("j")
while a != "x":
  window_style('The Spaceship Game','black','TODO') # FONDO DE COLOR BLANCO
  create_text(200,350,"The Spaceship Game",13.5,"CENTER","blue")
  create_text(200,300,"_Easy level (E)",10,"CENTER","white")
  create_text(200,250,"_Medium level (M)",10,"CENTER","white")
  create_text(200,200,"_Hard level (H)",10,"CENTER","white")
  create_text(200,150,"_Exit(X)",10,"CENTER","white")
 
  #--NIVEL FACIL--#
  if keypressed(2) == str("e"):
    print "Nivel facil"
    import time
    from modulepythong import *
    from math import sin, cos, pi
    window_style('The Spaceship Game','white','TODO') # FONDO DE COLOR BLANCO

    # Paisaje
    altura_paisaje = 400
    anchura_paisaje = 400
    window_coordinates(0, 0, anchura_paisaje, altura_paisaje)

    # Gravedad
    g = 0.00001

    # Nave
    tamanyo_nave = 10
    x = anchura_paisaje / 2
    y = altura_paisaje - 100
    vy = 0
    impulso_y = 2*g
    impulso_x = 0.00001
    vx = 0
    nave = create_filled_rectangle(x, y, x+tamanyo_nave, y+tamanyo_nave, 'blue')

    # Plataforma
    px = anchura_paisaje / 2
    py = 0
    vpx = .05
    anchura_plataforma = 40
    altura_plataforma = 3
    plataforma = create_rectangle(px, py,px+anchura_plataforma, py+altura_plataforma, 'red')

    # Tanque de combustible
    color = "green" # combustible lleno
    fuel = 1000
    consumo = 0.1
    rect_inicio = create_rectangle(0,altura_paisaje, 10, altura_paisaje-100, 'black')
    lleno = create_filled_rectangle(1,altura_paisaje, 9, altura_paisaje-fuel/10, color)
    create_text(25, altura_paisaje-8, '0%', 10, 'W')
    create_text(30, altura_paisaje-95, '100%', 10, 'W')

    # Dial de velocidad
    circulo = create_circle(anchura_paisaje-50, altura_paisaje-50, 50, 'black')
    for i in range(0, 360, 10):
      create_line(anchura_paisaje-50 + 40 * sin(i*pi/180), \
      altura_paisaje-50 + 40 * cos(i*pi/180), \
      anchura_paisaje-50 + 50 * sin(i*pi/180), \
      altura_paisaje-50 + 50 * cos(i*pi/180),)
      if i % 30 == 0:
        create_text(anchura_paisaje-50 + 30 * sin(i*pi/180), \
        altura_paisaje-50 + 30 * cos(i*pi/180), str(i), 5, 'CENTER')

        aguja = create_line(anchura_paisaje-50, altura_paisaje-50, \
        anchura_paisaje-50 + 50 * sin(0*pi/180), \
        altura_paisaje-50 + 50 * cos(0*pi/180),"black")

    facil = create_text(200,200,"Level Easy",12,"CENTER","blue")
    time.sleep(2)
    erase(facil)    
    # Simulacion
    while y > 0 and y < altura_paisaje and x > 0 and x < anchura_paisaje - tamanyo_nave:
      vy -= g
      if keypressed(1) == 'Up' and fuel > 0:
        vy += impulso_y
        fuel -= consumo
        if fuel < 350:
          color = "red" # combustible vaciandose
    
      elif keypressed(1) == 'Left' and fuel > 0:
        vx -= impulso_x
        fuel -= consumo
        if fuel < 350:
          color = "red" # combustible vaciandose
    
      elif keypressed(1) == 'Right' and fuel > 0:
        vx += impulso_x
        fuel -= consumo
        if fuel < 350:
          color = "red" # combustible vaciandose
      
      y += vy
      x += vx
      px += vpx
  
      if px <= 0 or px >= anchura_paisaje - anchura_plataforma:
        vpx = -vpx
      move(nave, vx, vy)
      move(plataforma, vpx, 0)

      viejo_lleno = lleno
      lleno = create_filled_rectangle(1,altura_paisaje, 9, altura_paisaje-fuel/10, color)
      erase(viejo_lleno)
      vieja_aguja = aguja
      aguja = create_line(anchura_paisaje-50, altura_paisaje-50, \
      anchura_paisaje-50 + 50 * sin(1000*vy*pi/180), \
      altura_paisaje-50 + 50 * cos(1000*vy*pi/180), 'black')
      erase(vieja_aguja)

    msg_x = anchura_paisaje/2
    msg_y1 = altura_paisaje/2
    msg_y2 = altura_paisaje/3

    if y >= altura_paisaje:
      create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
      create_text(msg_x, msg_y2, 'Rumbo a las estrellas?', 12, 'CENTER')

    elif y <= 0 and vy < -0.1:
      create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
      create_text(msg_x, msg_y2, 'Te has estrellado.', 12, 'CENTER')

    elif y <= 0 and \
    abs((px+anchura_plataforma/2)-(x+tamanyo_nave/2)) >= anchura_plataforma/2:
      create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
      create_text(msg_x, msg_y2, ' !Que mala puntería!', 12, 'CENTER')

    elif x <= 0 or x >= anchura_paisaje - tamanyo_nave:
      create_text(msg_x, msg_y1, 'Perdiste', 24, 'CENTER')
      create_text(msg_x, msg_y2, 'Chocaste con la pared.', 12, 'CENTER')

    else:
      create_text(msg_x, msg_y1, 'Ganaste', 24, 'CENTER')
      create_text(msg_x, msg_y2, ' !Enhorabuena, piloto!', 12, 'CENTER')

    time.sleep(4) 
    erase(nave)
    erase(plataforma)
    erase(rect_inicio)
    erase(lleno)
#-----------------------------------------------------------------# 
  elif keypressed(2) == str("m"):
    print "Nivel medio"
      
  elif keypressed(2) == str("h"):
    print "Nivel dificil"
    
#-----------------------------------------------------------------#
         
  elif keypressed(2) == str("x"):
    print "Saliendo..."
    a = keypressed(2)
    

  else:
    error = create_text(200,50,"Error! Press another key",11,"CENTER","red")
    time.sleep(2) # Espera 2 segundos y borra el objeto(mensaje)
    erase(error)

    
print"salistes"

Setup(setup.py)

Código:
from cx_Freeze import setup, Executable


setup(
    name = "" ,
    version = "0.1" ,
    description = "" ,
    executables = [Executable("menu_libro_blanco.py")]
    )

Bueno, te digo he utilizado la librería modulepythong para la creación, y ya he compilado otros programas sin librería y los compila bien.

Les facilito URL de los programas que utilice
http://www3.uji.es/~dllorens/downloads/pythong/
http://cx-freeze.sourceforge.net/


Les agradezco toda la ayuda.

Última edición por Enjavado; 05/08/2013 a las 10:09
  #8 (permalink)  
Antiguo 05/08/2013, 11:57
ger84
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

con py2exe me compiló bien
Código Python:
Ver original
  1. #setupPy2exe.py
  2. from distutils.core import setup
  3. import py2exe
  4.  
  5. setup(
  6.     windows = [
  7.         {
  8.             "script": "menu_libro_blanco.py"
  9.         }
  10.     ],
  11. )

con cx_Freeze hay que ser mas explícito
Código Python:
Ver original
  1. #setupCx_Freeze.py
  2. import sys
  3. from cx_Freeze import setup, Executable
  4.  
  5. # Dependencies are automatically detected, but it might need fine tuning.
  6. build_exe_options = {"packages": ["random","time","Tkinter","modulepythong","os","sys","threading","time","imp","warnings"]}
  7.  
  8. # GUI applications require a different base on Windows (the default is for a
  9. # console application).
  10. base = None
  11. if sys.platform == "win32":
  12.     base = "Win32GUI"
  13.  
  14. setup(  name = "",
  15.         version = "0.1",
  16.         description = "",
  17.         options = {"build_exe": build_exe_options},
  18.         executables = [Executable("menu_libro_blanco.py", base=base)])

Y en ambos casos copié menu_libro_blanco.py en la misma carpeta que quedó el .exe, no es la solución mas elegante, pero a mí me funcionó
  #9 (permalink)  
Antiguo 06/08/2013, 05:00
Enjavado
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

Gracias ger84:

De momento me lanza un error, pero creo que es pq el sistema que utilizo en de 64 bits, lo voy a probar después en mi casa, que es de 32.

Desde que me corra bien te lo hago saber, para decirte como me fue.

Muchas gracias amigo
  #10 (permalink)  
Antiguo 09/08/2013, 14:14
Enjavado
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

Hola de nuevo ger84:

Mira he hecho lo mismo que tu, y no se abre, lo único que me abre, es el archivo .py, pero el exe no lo logro abrir, y otra cosa el archivo, si borro python, no abre, lo probé, con otro que si me dejo hacer el .exe

Ya no se lo que hacer para que me funcione
Un saludo
  #11 (permalink)  
Antiguo 10/08/2013, 18:00
ger84
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Convertir .py en .exe en Python

Cita:
Iniciado por Enjavado Ver Mensaje
Hola de nuevo ger84:
Ya no se lo que hacer para que me funcione
Un saludo
Si, he caído en la cuenta que hay algún error por ahí dando vueltas, creo que tiene que ver con los imports, en particular de StringIO, hay que buscarlo...
  #12 (permalink)  
Antiguo 13/08/2013, 23:11
 
Fecha de Ingreso: julio-2013
Ubicación: México
Mensajes: 10
Antigüedad: 10 años, 8 meses
Puntos: 0
Respuesta: Convertir .py en .exe en Python

usando Gui2exe con py2exe me aparece este error:

error: libiomp5md.dll: No such file or directory

alguien sabe como puedo solucionarlo?

Etiquetas: python3
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:44.