views:

595

answers:

2

Hi, I'm trying to make a simple hello-world executable python gui app in windows using pyqt. So I've made the pyqt.py file

import sys
from PyQt4.QtGui import *
app = QApplication(sys.argv)
button = QPushButton("Hello World", None)
button.show()
app.exec_()

I tried to use py2exe with the following setup.py script:

from py2exe.build_exe import py2exe
from distutils.core import setup

setup( console=[{"script": "pyqt.py"}] )

(I had the No module named sip error first, but it's solved thanks to the Py2exeAndPyQt page).

Now I have the executable and when i try to run it, I get the following error:

Traceback (most recent call last):
  File "pyqt.py", line 2, in <module>
  File "PyQt4\QtGui.pyc", line 12, in <module>
  File "PyQt4\QtGui.pyc", line 10, in __load
ImportError: No module named QtCore

How can I fix it? TIA

+2  A: 

Add from PyQt4.QtCore import * to pyqt.py.

I'm not sure why it wasn't auto-included, but I think it has something to do with QtCore only being used by QtGui, which is a C++ lib... Like, py2exe only auto-detects python dependencies... So you have to import it manually.

Jesse Aldridge
+2  A: 

You can do something like this, you don't need import *.

py2exe_opciones = {'py2exe': {"includes":["sip"]}}
script = [{"script":"pyqt.py"}]

setup(windows=script,options=py2exe_opciones)

And now will the program should work. I had the same error.

Here can read more.

Alquimista