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.

  • You may find What are the external dependencies of a Python executable? useful. – user40980 Jun 19 '13 at 0:02
  • Very often, these standalone 'executables' aren't 'standalone' at all. Think about it: almost everything you run can (and is usually) 'interpreted' by your operating system -- this is why you have builds for Windows, the Mac, and for various flavors of Linux. While the 'level of interpretation' goes down considerably for lower-level languages like C and C++, they aren't often compiled for the hardware to interpret all by itself. – Sean Allred Jun 19 '13 at 0:09
  • 1
    "Compiling python" is often "packaging the python runtime into a native executable, and running it." Not always - but often. And it won't be cross platform anymore. – user40980 Jun 19 '13 at 0:44

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.

  • 2
    As a practical consideration, I would use pyinstaller or cx_freeze for packaging a python program rather than py2exe. Those two are actively developed, while the last py2exe release was in 2008. – Velociraptors Jun 19 '13 at 3:02
  • Thanks for the pointers @Velociraptors - it's been a while since I had to make a self-contained app in Python. – orlenko Jun 19 '13 at 4:22
  • 1
    So in other words, you're not really translating anything with a python 'compiler', you're just putting enough of the python interpreter into an executable to be able to run your code, so those without python can run it. Thanks! – Daynil Jun 24 '13 at 16:28

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.