61

I need to package my Python application, its dependencies, and Python itself into a single MSI installer for distribution to users. The end result should desirably be:

  • Python is installed in the standard location
  • the package and its dependencies are installed in a separate directory (possibly site-packages)
  • the installation directory should contain the Python uncompressed and a standalone executable is not required
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Florian Bösch
  • 27,420
  • 11
  • 48
  • 53
  • http://stackoverflow.com/questions/2933/how-can-i-create-a-directly-executable-cross-platform-gui-app-using-python – nbro May 19 '15 at 02:23

7 Answers7

31

Kind of a dup of this question about how to make a python into an executable.

It boils down to:

py2exe on windows, Freeze on Linux, and py2app on Mac.

Community
  • 1
  • 1
pjz
  • 41,842
  • 6
  • 48
  • 60
  • 4
    Not really a dup. This is specific to packaging. That other guy has not a clue yet. But cool, that's for the info about py2exe – d-_-b Aug 09 '10 at 05:42
  • Making a single executable (rather than installer) is not the only or even the best option. So definitely not a duplicate. – ivan_pozdeev Jun 13 '23 at 12:57
18

I use PyInstaller (the svn version) to create a stand-alone version of my program that includes Python and all the dependencies. It takes a little fiddling to get it to work right and include everything (as does py2exe and other similar programs, see this question), but then it works very well.

You then need to create an installer. NSIS Works great for that and is free, but it creates .exe files not .msi. If .msi is not necessary, I highly recommend it. Otherwise check out the answers to this question for other options.

Csa77
  • 649
  • 13
  • 19
dF.
  • 74,139
  • 30
  • 130
  • 136
6

My company uses the free InnoSetup tool. It is a moderately complex program that has tons of flexibility for building installers for windows. I believe that it creates .exe and not .msi files, however. InnoSetup is not python specific but we have created an installer for one of our products that installs python along with dependencies to locations specified by the user at install time.

Mike
  • 3,663
  • 3
  • 20
  • 12
  • That has nothing to do with bundling Python deps and code. Its still a giant mess, better to have Python and pip installed and distribute via pypi – demberto Mar 29 '22 at 18:44
4

I've had much better results with dependencies and custom folder structures using pyinstaller, and it lets you find and specify hidden imports and hooks for larger dependencies like numpy and scipy. Also a PITA, though.

wwwslinger
  • 936
  • 8
  • 14
3

py2exe will make windows executables with python bundled in.

Community
  • 1
  • 1
William Keller
  • 5,256
  • 1
  • 25
  • 22
1

py2exe is the best way to do this. It's a bit of a PITA to use, but the end result works very well.

Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114
1

Ok, I have used py2exe before and it works perfectly except for one thing... It only works on executable windows machines. I then learned about Jython which turn a python script into a .Jar file. Which as you know is executable from any machine that has Java ("To your latest running version") installed. Which is great because both unix, windows, and ios (Most of the time) Run java. That means its executable from all of the following machines. As long as they run Java. No need for "py2mac + py2exe + freeze" just to run on all operating systems. Just Jython

For more information on how it works and how you can use it click here.
http://www.jython.org/

Note that jython supports Python 2 only (at time of writting).

Top-Master
  • 7,611
  • 5
  • 39
  • 71