I’ve started learning my first language recently, Python, and I became interested in how it differed from the myriad of other programming languages.
I’ve been able to find most of it out with some searching:
There is interpreted, compiled and assembly language. Then there is numerical machine code (which as I understand is just binary?) that is read by hardware directly. So Python is an interpreted language because it isn’t explicitly compiled to machine code (although from what I understand this is a false distinction since most code is both compiled and interpreted, if only behind the scenes).
I still have one question I couldn’t figure out how to search an answer for. I assume Python code requires the Python platform to be read because it contains the interpreter. But how do you get those “standalone” .exe programs which you can run on most computers? Are those files just using a platform which every computer has by default, or are these files that are already compiled completely to machine code? (Like with C++?)
The main reason I’m wondering this is that I was wanting to send someone my simple Python programs without having them install the platform. I’ve searched online and found some ‘compilers?’ that will do this, but they don’t seem to work very well and are very difficult to work with.
3
MichaelT’s comment is spot-on. Things like py2exe do the following:
- bundle python runtime for a particular platform with your python code and all its dependencies
- create a self-extracting executable that unpacks all of the above things and kicks off your script
You get a ready-to-run package for a single platform. You sacrifice portability.
3
The interpreters themselves are compiled and dependent on the platform they run on due to different OS and architecture concerns (for example different C libraries and file handling). So there is no way to get around the platform dependency entirely in the installation. However as you say there are ways to package it into a package so that it will be easier for distributing to the user who need not install the interpreter and other dependencies.
PyInstaller seems to be able to do what you want with not too much fuss and can build packages for the most common platforms and is easy to run. The main thing I found with Windows is that you need to also install PyWin32 (making sure to get the correct bitness depending on the version of Python you have installed).