Python is an interpret language but if it is true does it mean that we have to distribute source code while distributing program | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 4

Python is an interpret language but if it is true does it mean that we have to distribute source code while distributing program

22nd Apr 2017, 9:48 AM
shobhit
shobhit - avatar
4 Antworten
+ 6
You can "compile" it to an executable, but this single file will still contain the whole interpreter and all imported modules. You might end up with a 45MB file just printing "Hello world" :)
22nd Apr 2017, 11:23 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
There are a few ways to make a .py script .exe-cutable. py2exe, cx_freeze or nuitka modules come to my mind. However, as Python is an interpreted, not a compiled language, those modules pack everything into the executable - including the interpreter itself, all the needed modules, external files (textures, media, etc). This is then called 'a build'. So your output file (or folder, if you're going easy and allow those builds to be folders with all those files you imported and just include one executable to run) might get very heavy, quickly. The interpreter alone may weight some 30-40MB, although there are ways to get it a bit lower. The big advantage of such a solution is that it will run everywhere-ish* even when there is no Python installed on the machine. But it will not be too efficient, as it will have to unpack everything into RAM each time it is executed. There is no right or wrong here, you just need to know how it works and accept that. * - it gets tricky when you have a 64-bit Python and compile a file you want to later run on a 32-bit version - it won't go. Pls make sure you make your build in the lowest possible settings or be prepared to produce several "compilation" versions. That will maximize the chance for your project to run everywhere.
23rd Apr 2017, 5:20 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
no. there are various ways to create an executable out of a .py file.
22nd Apr 2017, 10:06 AM
Bebida Roja
Bebida Roja - avatar
+ 2
@Kuba sir, I didn't get what you said. A simple illustration would be helpful :)
23rd Apr 2017, 3:15 AM
Tamoghna Saha