Py2exe simplifier

Tags: programming.
By lucb1e on 2012-03-23 23:30:14 +0100

Just a quick post: It took me way too long to find out how I should convert .py files to executables with py2exe. I just want to give it an input file, and let it figure out the rest by itself. After I found out I thought, this should be easily automated. And so it was.

Prerequisites for this:
- Python installed (example directory is C:\>Python27)
- py2exe installed

Put the following script in your Python directory and name it py2exe.cmd
@echo off

echo Path to .py file to compile (relative from the Python directory):
set /p file=
echo from distutils.core import setup>install
echo import py2exe>>install
echo.>>install
echo setup(console=['%file%'])>>install
python install install
python install py2exe


Next, go to your python directory (like C:\>Python27) in Windows Explorer or command or however you like. Doubleclick (or otherwise start) the py2exe script. Type the path/filename to the .py file as asked on-screen. Hit enter. Wait. When the window closes, your exe (with the huge load of required files) will be in the \python27\dist folder.

This even sounds harder than it is :)
The script is really quick and dirty by the way, it doesn't clean up any temporary files or so. Not that it really needs to, there is only one temp file, but still... Well, feel free to improve. The code is free to use and modify and distribute and anything (for commercial and non-commercial purposes) without credits or anything else needed.

I hope this was helpful, and happy converting :)
lucb1e.com
Another post tagged 'programming': Fastest SELECT query

Look for more posts tagged programming.

Previous post - Next post