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.

4
  • For Windows there exists py2exe: stackoverflow.com/questions/4158369/… Commented Apr 4, 2015 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). Commented Apr 4, 2015 at 10:30
  • 1
    @TrickyInt so why not mention that? What have you tried, and how precisely is it failing to work? Commented Apr 4, 2015 at 13:37
  • possible duplicate of Compiling Python to native code? Commented Apr 5, 2015 at 20:04

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

How does these handle external modules - is this well supported?
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.
Okay, that might be the problem. I didn't import all modules in the main file. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.