We have a Py module we'd like to give to users in the form of a windows executable. Is there a good tried and true tool to package a py module to Windows exe?
-
@mgilson you should make that an answer rather than a comment.– DuncanCommented Jul 23, 2012 at 13:16
-
3Note that there aren't solutions that will compile Python in to opaque byte or machine code, really, only tools that will give you the ability to distribute a 1-click-runnable Python program.– Silas RayCommented Jul 23, 2012 at 13:16
-
@mgilson we did, but it currently depends on/built for py2.6 our dev environment is set for py 2.7– rdodevCommented Jul 23, 2012 at 13:20
-
@sr2222 that's exactly what we're looking for. Not looking for a compiler but rather for a "standalone" executable for machines w/o py.– rdodevCommented Jul 23, 2012 at 13:21
-
@Duncan -- I didn't feel confident enough to make it an answer as I've never used py2exe myself. I've just seen it referenced a bunch of times.– mgilsonCommented Jul 23, 2012 at 13:23
3 Answers
As an alternative to py2exe
if you're running a 3.x version of Python, you can use cx_freeze
(http://cx-freeze.sourceforge.net/). It doesn't package the program into a single executable, but you can package all the files it generates into a self-extracting archive for deployment. See https://stackoverflow.com/a/11511735/369977 for details.
You can use Python extention py2exe.
In Python you can use the code:
from distutils.core import setup
import py2exe
setup(console=['test.py'])
to make the executable test.exe
-
Aye, I was few secs to late. I see we Googled the same code :)– GunnarCommented Jul 23, 2012 at 13:18
-
I just stole the tutorial directly from their website Commented Jul 23, 2012 at 13:19
-
likewise here. I don't understand why @Syrahn didn't Google it before asking. It was the first thing that popped up on the serach.– GunnarCommented Jul 23, 2012 at 13:21
-
@Gunnar I did Google it before asking. Don't jump to conclusions. Firstly the project seems to have been abandoned since 2008, secondly it's only compatible with Py 2.6– rdodevCommented Jul 23, 2012 at 13:26
-
@Syrahn, really? There is a py2exe package for Python 2.7 in SourceForge.– RaceymanCommented Jul 23, 2012 at 14:08
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
So long as you have py2exe installed it will compile hello.py
to an exe, (it actually just bundles the stdlib and interpreter into an executable.)