1

To preface, I have very little python knowledge, so the simplest solution will probably be the best one.

Essentially, I've written a program that takes user input and writes it to a text file. I've created a GUI with Qt and PySide. What I want to do now is to compile everything together to be a single .exe file that I can just drop into the laps of anyone who wants to use it. Basically, it needs to be able to run out of 1 single .exe file on a computer that doesn't necessarily have any of the python libraries installed that mine does.

The only imports on the program are

import sys
from PySide.QtCore import *
from PySide.QtGui import *
from math import *

in case those are important to the compiling. Thank you for the help, I appreciate it.

P.S. It's for my grandmother, who has nearly no knowledge of computers whatsoever. If possible, it'd be awesome if it would just...open. I don't mind if it has to run something in cmd to install all the python stuff, as long as the .exe from which the program runs is still JUST an .exe.

N_A
  • 19,799
  • 4
  • 52
  • 98
Ian Zane
  • 2,209
  • 5
  • 23
  • 21

2 Answers2

1

download pyinstaller (http://www.pyinstaller.org/)

open your cmd prompt

cd folder
c:\pyinstaller\pyinstaller.py --noconsole --onefile my_script.py

the exe should be found in the dist folder that is created

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • Downloaded it, but when I double-clicked setup.py within the extracted folder, it just flashed cmd and didn't create the directory you specified. I feel like an idiot, but how do I install it? – Ian Zane May 15 '13 at 21:48
  • you read the directions? anyway you just extract it ... it very specifically says "Do not run setup.py directly" ... if you extract it to say `C:\pyinstaller` it should have a `pyinstaller.py` that is in that directory you simply call that (from the folder where your python file is) with the above command – Joran Beasley May 15 '13 at 21:50
  • My apologies, I found the documentation just after posting the comment. Also, it did create the .exe, but doesn't seem to work. It ran perfectly well in python, but when I run the created .exe, nothing happens at all. – Ian Zane May 15 '13 at 22:12
  • can you post your script somewhere and provide a link? you may need `--console` instead of noconsole ... – Joran Beasley May 15 '13 at 22:25
1

I suspect your grandmother uses windows in which case I would recommend using py2exe. Here is probably all than you need... 1). create the below script and modify the last line of it to be the name of the actual script (see its last line)

#execmaker.py would be the name of this file
#stable version
from distutils.core import setup
import py2exe

includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
            'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
            'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
                'tk84.dll']

setup(
    options = {"py2exe": {"compressed": 2, 
                          "optimize": 2,
                          "includes": includes,
                          "excludes": excludes,
                          "packages": packages,
                          "dll_excludes": dll_excludes,
                          "bundle_files": 3,#dont bundle else unstable
                          "dist_dir": "dist",
                          "xref": False,
                          "skip_archive": False,
                          "ascii": False,
                          "custom_boot_script": '',
                         }
              },
    windows=['My_Script.py'] #this is the name of your actual script 
)

2). Then you can go to the directory where this script and your actual script resides via cmd and then type

python execmaker.py py2exe

You now should have a working executable. Now a you can double click on the executable and your script will run. oh yeah and if you have questions follow this guy's instructions...he is good!

http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/

Sason Torosean
  • 562
  • 3
  • 18
  • Everything worked! Also, for some reason, it ran when I put just `execmaker.py py2exe` into cmd. For some reason it doesn't recognize `python` as a function. But it works. It does create a bunch of files though. Any way to have it build the application as a single file? – Ian Zane May 16 '13 at 02:05
  • I am glad it did the trick. The reason it didn't recognize python is because you need to do this little trick involving adding python to the path detailed here... http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7. If you change the bundle_files parameter it should make a more tidy final product...check out the link I posted. – Sason Torosean May 16 '13 at 02:31