1

Is it in any way possible too compile a python script into a standalone program, that would be possible to run on another machine that does not have python installed?

Preferably in a way that the script (or, compiled program) would be able to be installed on other machines, so that it's not just a random file but an actual program that can be launched from the start menu on windows.

Being able to do this in windows is the minimum, but if any cross-platform method exists that would be a big plus.

Any help appreciated.

TrickyInt
  • 157
  • 1
  • 8
  • For Windows there exists py2exe: http://stackoverflow.com/questions/4158369/can-i-somehow-compile-a-python-script-to-work-on-pc-without-python-installed – SmCaterpillar Apr 04 '15 at 10:25
  • Yes, i have done quite a bit, and i have tried using pyinstaller (Alternative to py2exe). But the problem being that i couldn't get any of the extra modules necessary working (Requests in this case). – TrickyInt Apr 04 '15 at 10:30
  • 1
    @TrickyInt so why not mention that? What have you tried, and how precisely is it failing to work? – jonrsharpe Apr 04 '15 at 13:37
  • possible duplicate of [Compiling Python to native code?](http://stackoverflow.com/questions/8786203/compiling-python-to-native-code) – Toby Allen Apr 05 '15 at 20:04

1 Answers1

2

Actually, there are at least two decisions, as of April, 2015 both work with both Python 2 and 3. Both I have personally used and can confirm working.

1. cx_Freeze

http://cx-freeze.sourceforge.net/

Works with Windows, OS X and Linux, although you have to compile (or should I say, "freeze") your app on each system. You may use compile your code on different machines or just use virtual machine. Beware that you should use 32-bit Python if you want your app to run on 32-bit systems and compile against it!

2. py2exe

http://www.py2exe.org/

It has added support of Python 3 just recently. The advantage is that it is possible to wrap the whole program in single executable, while with cx_Freeze you usually end up with Python itself in one file, all your dlls and pythons libraries in separate files and all your code in library.zip file, which is compiled to .pyc files, but this operation is easily reversable, so beware that some of your users might easily hack your software! The main disadvantage of py2exe is that it is Windows-only.

Megan Caithlyn
  • 374
  • 2
  • 11
  • 33
  • How does these handle external modules - is this well supported? – TrickyInt Apr 04 '15 at 11:13
  • I'm using tens of external modules in my project (no joke!). Just be sure to import all of them in your main file, even if it seems to be out of place. Sometimes you'll have to import their dependencies, although that import line is unnecessary when the app is not frozen. Depends on the situation. Just try cx_Freeze and if it fails examine what is it failing to import and post here, maybe I can help. – Megan Caithlyn Apr 04 '15 at 14:36
  • 1
    Okay, that might be the problem. I didn't import all modules in the main file. Thank you. – TrickyInt Apr 04 '15 at 20:32