Hey ya guys, it's my first topic on DaniWeb, sounds like a good place to find help with programming. :)

Today I'm trying to compile a simple code made for PyQt4 using cx_Freeze, but I'm getting an error, I'll show you all the codes:

example.pyw

import sys
from PyQt4 import QtGui


def main():

    app = QtGui.QApplication(sys.argv)

    w = QtGui.QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Example')
    w.show()

    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

setup.py

from cx_Freeze import setup, Executable

includes = ["sip","re"] 
exe = Executable(
    script="example.pyw",
    base="Win32GUI"
    )
 
setup(
    options = {"build_exe": {"includes":includes}},
    executables = [exe]
    )

After compiling the code, while trying to run the .exe I'm getting the following error:

cx_Freeze: Python error in main script

Traceback (mot recent call last):
 File "C:\Python\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in <module>
  exec(code, m.__dict__)
 File "example.pyw", line 2, in <module>
 File "ExtensionLoader_PyQt4_QtGui.py", line 12, in <module>
ImportError: No module named QtCore
Member Avatar for nabla2

Try add from PyQt4 import QtGui, QtCore. I have another cx_Freeze error: No module named atexit. If you get similar error just add module to includes in setup.py.

This code works for me:

from cx_Freeze import setup, Executable

includes = ["atexit"] 
exe = Executable(
    script = "example.pyw",
    base = "Win32GUI"
    )
 
setup(
    options = {"build_exe": {"includes": includes}},
    executables = [exe]
    )

@nabla2

While trying this code:

setup.py

from cx_Freeze import setup, Executable
from PyQt4 import QtGui, QtCore

includes = ["sip","re","atexit"] 
exe = Executable(
    script="example.pyw",
    base="Win32GUI"
    )
 
setup(
    options = {"build_exe": {"includes":includes}},
    executables = [exe]
    )

I got the same error while executing the .exe.

Even trying to include PyQt at all I'm getting the same error.

from cx_Freeze import setup, Executable

includes = ["sip","re","atexit","PyQt4"] 
exe = Executable(
    script="example.pyw",
    base="Win32GUI"
    )
 
setup(
    options = {"build_exe": {"includes":includes}},
    executables = [exe]
    )

Are you not having troubles while compiling PyQt4 codes with cx_Freeze?

Member Avatar for nabla2

You forgot to add from PyQt4 import QtCore to your example.pyw file. Alternatively you can add PyQt4.QtCore to includes:

from cx_Freeze import setup, Executable

includes = ["atexit", "PyQt4.QtCore"] 
exe = Executable(
    script = "example.pyw",
    base = "Win32GUI"
    )
 
setup(
    options = {"build_exe": {"includes": includes}},
    executables = [exe]
    )
commented: He solved my problem. :) +0
commented: nice info +13

nabla2

I added

includes = ["sip","re","atexit","PyQt4.QtCore"]

to my setup.py and it worked well, i do appreciate your help, pal. :)

SOLVED

By the way, I checked that just adding

includes = ["PyQt4.QtCore"]

to setup.py, it works same way. :)

setup.py
from cx_Freeze import setup, Executable

includes = ["pk_DOMI","pk_Fil"]
exe = Executable(
script = "Inserted_sortedFN.py",
base = "Win32GUI"
)
setup(
options = {"build_exe": {"includes": includes}},
executables = [exe]
)
After compiling the code, while trying to run the .exe in cmd I'm getting the following error:
ImportError: No module named pk_DOMI

No module named pk_DOMI
means that cx_Freeze can't find the mnodule, or you don't have it.

BTW, if you really want help don't hijack old solved posts. Most helpful folks won't look there for your problem. Start a new thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.