Foros del Web » Programando para Internet » Python »

Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Estas en el tema de Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze en el foro de Python en Foros del Web. Bueno logré terminar el primer programita para gestionar items para un juego todo funciona perfecto. Pero ahora viene la hora de transformarlo en un ejecutable. ...
  #1 (permalink)  
Antiguo 01/04/2012, 19:42
 
Fecha de Ingreso: octubre-2010
Mensajes: 73
Antigüedad: 13 años, 6 meses
Puntos: 0
Pregunta Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Bueno logré terminar el primer programita para gestionar items para un juego todo funciona perfecto. Pero ahora viene la hora de transformarlo en un ejecutable.

Estoy usando Python 3.2, PyQt 4.8
S.O: Windows 7 x64

Y según estuve investigando para hacer esto se usa py2exe , pero funciona bien parece hasta python 3.1, intente hacerlo andar y NADA.

Así que encontre cx_Freeze ([URL="http://cx-freeze.sourceforge.net/cx_Freeze.html"]http://cx-freeze.sourceforge.net/cx_Freeze.html[/URL]).

Logré crear el Ejecutable .EXE pero cuando lo abro me tira que QSql Database: QMYSQL driver not loaded.

Armé uno de prueba para que vean aver si se les ocurre:

Código:
import sys
from PyQt4 import QtCore, QtGui, QtSql

from test_para_instalar_vista import Ui_ventana_principal_vista

class Principal (QtGui.QMainWindow):
    
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        
        self.ventana = Ui_ventana_principal_vista()
        self.ventana.setupUi(self)
          
        self.ventana.data_base = QtSql.QSqlDatabase.addDatabase('QMYSQL')
        self.ventana.data_base.setHostName("poner un ip o dns")
        self.ventana.data_base.setDatabaseName("poner database")
        self.ventana.data_base.setUserName("poner usuario")
        self.ventana.data_base.setPassword("poner contraseña")
        self.ventana.data_base.open()
            
        self.ventana.lineEdit_se_conecto_o_no.setText( str (self.ventana.data_base.open()))
         
if __name__ == '__main__':
    #Instancio la aplicacion (necesario para que levante el driver de mysql y todo)
    app = QtGui.QApplication(sys.argv)
    #    detectar_ips()
    ventana = Principal()
    ventana.show()    
    sys.exit(app.exec_())

Y la vista:

Código:
# -*- coding: utf-8 -*-

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_ventana_principal_vista(object):
    def setupUi(self, ventana_principal_vista):
        ventana_principal_vista.setObjectName(_fromUtf8("ventana_principal_vista"))
        ventana_principal_vista.resize(682, 477)
        ventana_principal_vista.setStyleSheet(_fromUtf8("QWidget {\n"
"    background-color: rgb(94, 94, 94);\n"
"}"))
        self.centralwidget = QtGui.QWidget(ventana_principal_vista)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.lineEdit_se_conecto_o_no = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_se_conecto_o_no.setGeometry(QtCore.QRect(300, 220, 113, 20))
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.lineEdit_se_conecto_o_no.setFont(font)
        self.lineEdit_se_conecto_o_no.setObjectName(_fromUtf8("lineEdit_se_conecto_o_no"))
        ventana_principal_vista.setCentralWidget(self.centralwidget)

        self.retranslateUi(ventana_principal_vista)
        QtCore.QMetaObject.connectSlotsByName(ventana_principal_vista)

    def retranslateUi(self, ventana_principal_vista):
        ventana_principal_vista.setWindowTitle(QtGui.QApplication.translate("ventana_principal_vista", "Ventana Principal de Test Instal", None, QtGui.QApplication.UnicodeUTF8))
El build:

Código:
from cx_Freeze import setup, Executable

setup(
        name = "hello",
        version = "0.1",
        description = "the typical 'Hello, world!' script",
        executables = [Executable("test_para_instalar.py")])

Y otro problema es que tampoco abre las imagenes del rc




Saludos.-
__________________
Página Principal: http://www.almightysystem.com.ar/
  #2 (permalink)  
Antiguo 01/04/2012, 22:50
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Para windows te recomendaría crear el binario usando py2exe.
  #3 (permalink)  
Antiguo 02/04/2012, 08:22
 
Fecha de Ingreso: octubre-2010
Mensajes: 73
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Bueno probe otra ves usando py2exe y me tira de error

Código:
C:\Python32\MyPrograms>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    import py2exe
  File "C:\python32\lib\site-packages\py2exe\__init__.py", line 67, in <module>
    import distutils.dist, distutils.core, distutils.command, build_exe, sys
ImportError: No module named build_exe
setup:

Código:
from distutils.core import setup
import py2exe

setup(console=['test_para_instalar.py'])
ya no se me ocurre que hacer =/
__________________
Página Principal: http://www.almightysystem.com.ar/
  #4 (permalink)  
Antiguo 02/04/2012, 10:47
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

En vez de:
Código:
C:\Python32\MyPrograms>python setup.py install
intenta con:
Código:
C:\Python32\MyPrograms>python setup.py py2exe
Nota: Acabo de darme cuenta que estas intentado usar python3.2 te recomendaría usar python 2.7 en lo que python 3.x se vuelve mas maduro. Otra cosa es que py2exe funciona solamente para versiones python 2.x.

Te recomiendo que te quedes con cx_freeze. Creo que esto te ayudara a resolver tus dudas.
  #5 (permalink)  
Antiguo 02/04/2012, 21:39
 
Fecha de Ingreso: octubre-2010
Mensajes: 73
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Por lo que vi dicen que hay que agregar sys en el import del freeze.py

lo hice pero al compilar no me tira error, me tira error al abrir el programa que me dice:

Código:
QsqlDatabase: QMYSQL driver not loaded
QsqlDatabase: available drivers:
QsqlQuery::exec: databse not open
QsqlQuery::exec: databse not open
que dolor de cabeza T_T
__________________
Página Principal: http://www.almightysystem.com.ar/
  #6 (permalink)  
Antiguo 04/04/2012, 07:01
 
Fecha de Ingreso: octubre-2010
Mensajes: 73
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Después de hacer pruebas y pruebas pude sacar el problema.

Al parecer el build que genera no me está agregando el archivo "qt.conf" ni la carpeta de plugins de pyqt4

C:\Python32\Lib\site-packages\PyQt4

Agregando eso al build, sale andando perfectamente.

Agregamos la carpeta plugins de pyqt4

Y modifico qt.conf
Código:
[Paths]
Prefix = .
Binaries = .
plugins = plugins
__________________
Página Principal: http://www.almightysystem.com.ar/

Última edición por Onsterion; 04/04/2012 a las 11:11
  #7 (permalink)  
Antiguo 15/12/2012, 20:15
 
Fecha de Ingreso: marzo-2012
Mensajes: 1
Antigüedad: 12 años, 1 mes
Puntos: 0
Respuesta: Python 3.2 - PyQt 4 Crear EXE usando cx_Freeze

Cita:
Iniciado por Onsterion Ver Mensaje
Después de hacer pruebas y pruebas pude sacar el problema.

Al parecer el build que genera no me está agregando el archivo "qt.conf" ni la carpeta de plugins de pyqt4

C:\Python32\Lib\site-packages\PyQt4

Agregando eso al build, sale andando perfectamente.

Agregamos la carpeta plugins de pyqt4

Y modifico qt.conf
Código:
[Paths]
Prefix = .
Binaries = .
plugins = plugins
Estimado Onsterion,
Podrías poner el ejemplo del setup.py porque estoy en el mismo dilema que vos resolviste y no tengo idea de como hacerlo.
Desde ya muchas gracias
Claudio

Etiquetas: .exe, 3.2, onsterion, pyqt4
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 06:45.