-5

I was wondering what language are windows programs coded in? Can a python program run on windows if the computer doesn't have python installed?

  • 2
    Yes. Look at pyinstaller. This question, however, is too broad. – David Hoelzer Jul 25 '17 at 00:29
  • 1
    ..."what language"? You might start with [the PE executable format](https://en.wikipedia.org/wiki/Portable_Executable) specification. Other than that, it's platform-specific machine code. – Charles Duffy Jul 25 '17 at 00:30
  • And BTW, while you can easily wrap the Python interprer and your code up in an executable, it'll be just that -- the Python interpreter and your code wrapped up in a package. You won't get any of the performance or size benefits of a true compiled executable, and reverse-engineering will be trivial. – Charles Duffy Jul 25 '17 at 00:34
  • 3
    @user8360541 Are these two questions connected with each other? Why can you not have two separate questions? – MCG Jul 25 '17 at 00:46
  • `.exe` is just a container format for an executable windows program, some meta-info (entry point, segments, symbols/dependencies etc.) and the code itself in *machine language*. This is either the language the CPU understands directly (typically `i386` or `amd64`) or the `IL` (intermediary language) of `.NET` which is for a "*virtual* CPU" implemented by .NET's `CLR` (common language runtime) –  Jul 25 '17 at 06:36
  • It's the job of a *compiler* to translate a human-readable programming language to machine language. A compiler targeting windows will place the result in a `.exe` file. You can use any language when you have a windows compiler for it. If your `.exe` should contain *native* machine code, common choices are C, C++, but a lot of others are possible. The same holds for `IL` code, but the most common choice here is C#. –  Jul 25 '17 at 06:39
  • @Kyll well, Iwould not describe the question as spam, no. They are not trying to promote or sell anything. – Martin James Jul 25 '17 at 07:57
  • @Kyll maybe you should read it again? – Martin James Jul 25 '17 at 08:05
  • @MartinJames It's a short question by what seems to be a beginner, at least when it comes to executables and portable code. So? – Kyll Jul 25 '17 at 08:08
  • @Kyll they are the sort of questions, (more than one, and not well related), that someone would ask to waste others' time. They are far from what I would expect from a 'professional and/or enthusiast programmer' There has been a nasty outbreak of trolling recently, and if this question is not a troll, it makes a good attempt at impersonation. – Martin James Jul 25 '17 at 08:52

1 Answers1

4

I would recommend reading into this:

https://en.wikipedia.org/wiki/Portable_Executable

An EXE is a bundle of machine code. Take a look in a hex editor and grab an opcode manual. You probably won't be able to make sense of it without a lot of studying, but they're basically micro instructions.

To your other question, though. Yes, you can make an exe from a Python script. This works by bundling the python runtime with the script itself. Take a look at pyinstaller:

http://www.pyinstaller.org/

EDIT: As pointed out in the comments, use pyinstaller instead of py2exe. It is more actively maintained.

DavidBittner
  • 515
  • 2
  • 4
  • 15