Search code examples
pythonpython-3.xpyqt4cx-freeze

python3 & pyqt4 & cx_freeze: no module named 'sip'


I just recently learned some python & pyqt basics, and today i wanted to convert a program I made to exe. I'm using python 3.4.1 and PyQt4 installed via binary installer (my system is 32-bit Windows 7 Enterprise, if it makes any difference). So I found Cx_Freeze should be a viable tool for the job, but as for now, I have spent several hours trying to make it work.

I installed Cx_Freeze from this site (after installing it from pypi.python.org and getting some error considering modules; this version supposedly has a patch that fixed it), and this is (the current version of) my setup.py file:

import sys
from cx_Freeze import setup, Executable

build_exe_options = {"packages": ["re", "sip"]}

setup(
    name = "Project",
    version = "1.0",
    description = "desc",
    options = {'build_exe': build_exe_options},
    executables = [Executable("project.py", base = "Win32GUI")]
    )

So, when i run it in cmd (python setup.py build), it creates the build folder and everything, but when i try to run the project.exe inside I get this error message.

Among other, I also had tried having "re" and "sip" in includes (instead of packages). Also one of earlier versions had no specific options defined by me. Also tried simply copying several other setup files I could find on the net, and so on - yet nothing worked.

Thanks in advance for any help :))


Solution

  • Reposting as an answer:

    This is a bug that will be fixed in the next version of cx_Freeze. When it can't parse a code file as Python syntax, it tries to treat it as a compiled library, but that's not necessarily true (e.g. PyQt includes some separate files for Python 2 and 3). In the meantime, the simplest way to work around it is to apply the fix manually to your installed cx_Freeze, as described in this comment.