0

The accepted answer to this question deploying python applications discusses "embedding Python" in your installer to deploy it as an Exe.

I would like to take this approach to deploying a python app instead of using something like Py2exe. When I try to Google for "embedding python" the answer all seem to be about embedding python into C code. Can someone point me to a tutorial on embedding into your installation package?

Community
  • 1
  • 1
RedRaven
  • 725
  • 2
  • 18
  • 33
  • 1
    so you want to have an installer that installs python as part of the setup and then the user just has python? what are you building your installer with? – Joran Beasley Jan 08 '14 at 22:08
  • @JoranBeasley, or include it as a library in the installation, as the question I linked to mentions. Not sure if there is a difference/which one is easier – RedRaven Jan 09 '14 at 14:11
  • if you just want to make an exe look at pyinstaller then you can build an exe distributable with `c:\pyinstaller\pyinstaller.py --onefile my_main_script.py` but if you want to have general python be available on the host machine that doesnt quite do it (it includes an interpretter of your python install that only runs when you run your program exe) – Joran Beasley Jan 09 '14 at 15:46
  • 1
    the accepted answer talks about embedding Python (using it as a library) in *your application* (not in an installer -- it wouldn't make sense). And the answer explicitly says that other approaches usually a lot more powerful and robust. You could use cx_Freeze, PyInstaller, etc instead to create a standalone distribution for your Python application (including all necessary files for a python binary itself) e.g., it could be a single file that can be run directly on your platform (without requiring external Python installation) or pack generated files using Inno Setup. – jfs Jan 09 '14 at 16:16
  • @J.F.Sebastian: Thanks and that makes sense now, PyInstaller is what I was looking for. You want to make it an answer so I can accept? – RedRaven Jan 09 '14 at 17:44
  • @RedRaven: you could [post your own answer](http://stackoverflow.com/help/self-answer) if you think you found one. – jfs Jan 09 '14 at 18:22

1 Answers1

1

with inno-setup I know you can do it like this in your *.iss file

[Files]
Source: "python_installer.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall

[Run]
Filename: "{tmp}\python_installer.exe"; Check: pythonCheck


function pythonCheck(): Boolean;
begin
  Result := SOME_CONDITION_DO_WE_NEED_TO_INSTALL;
end;

(note that inno-setup iss files are pascal ...)

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I'm very new to this whole create installations thing, so I didn't even think about what to use to create the installer. But Inno looks interesting, let me investigate... – RedRaven Jan 09 '14 at 14:03
  • 1
    Joran, you don't need to worry about multiple `Check` function evaluations. In check functions you should never perform anything time or resource consuming, so it's not a problem let it evaluate several times. – TLama Jan 09 '14 at 15:26
  • 1
    of coarse using something like pyinstaller removes pretty much all of the headaches from making installers ...(although it wont install python on the host machine) @TLama thanks for the heads up – Joran Beasley Jan 09 '14 at 15:41