3

All,

I have developed a python program that is controlled by a GUI developed in PyQt. This GUI file, which was later converted to python (using pyuic4) implements about 4 other python files including a "main file". How could I convert all of these into one "double - clickable" .exe file? NOTE: My program and GUI both work when I run my main file.

Regards

sudobangbang
  • 1,406
  • 10
  • 32
  • 55

2 Answers2

4

You can use cxFreeze to build executable: http://cx-freeze.sourceforge.net/.

However, there will be a lot of files, but you could use your app standalone.

Also, you should be accurate in module imports to reduce size of the build. My scripts (about 200KB) were built in 200MB monster (used SciPy and Qt4).

Example build scripts is attached:

#coding=utf-8

from cx_Freeze import setup, Executable

includes = ["atexit"] 

buildOptions = dict(
    create_shared_zip=False,
    append_script_to_exe=True,
    includes=includes
)

executables = [
    Executable(
        script='main.py',
        targetName='projectname.exe',
        base="Win32GUI" # THIS ONE IS IMPORTANT FOR GUI APPLICATION
    )
]

setup(
    name="ProjectName",
    version="1.0",
    description="",
    options=dict(build_exe=buildOptions),
    executables=executables
)
soupault
  • 6,089
  • 4
  • 24
  • 35
  • "Win32GUI" would this be the same for me? seeing as I developed in QtDesigner for Windows 64 bit? Also, would I need to include the other files that are imported in my code into this? Or will it recognize them and manually combine all into one .exe as long as it is in the same directory? – sudobangbang Jun 17 '14 at 11:56
  • 1
    Yes, i'm using 64bit system/python/qt4 too. You should to add (to buildOptions) files you want to become .exe. Python "import" dependencies will mostly be autoincluded by cxFreeze. However, there are some exceptions: - http://stackoverflow.com/questions/8765568/py2exe-importerror-no-module-named-backend-tkagg; - 'scipy.special._ufuncs_cxx'; - 'scipy.sparse.csgraph._validation'; - 'scipy.sparse.linalg.dsolve'; - 'scipy.integrate.vode'; - 'scipy.integrate.lsoda'; - 'numpy.core.multiarray'; - maybe some more. – soupault Jun 17 '14 at 11:58
  • Awesome, I will test this out now. Is there a command/ certain flags youve found to work? – sudobangbang Jun 17 '14 at 12:05
  • Sorry, not to 'buildOptions', obviously, but to 'executables'. Flags? Like what? – soupault Jun 17 '14 at 12:08
  • Well, I am getting an error, with importing what I believe is matplotlib. Is there anyway I can give a flag to fix this? Error is: 'ImportError:No module named backend_tkagg' – sudobangbang Jun 17 '14 at 12:18
  • 1
    I gave you a link in previous comment. Simply add module name to 'includes' list. – soupault Jun 17 '14 at 12:21
  • Ah I see, it says to add that to the config file, do you know where cx_freeze creates this under the build folder? Or what name it would generate for it ? – sudobangbang Jun 17 '14 at 12:25
0

There are many tools to convert Python applications to executable files. I recommend to use cx_Freeze: http://cx-freeze.readthedocs.org/en/latest/

mguijarr
  • 7,641
  • 6
  • 45
  • 72