Executables With Python
Executables With Python
high-level
SOURCE CODE SOURCE CODE
language
print(„hello world“) print(„hello world“)
COMPILER INTERPRETER
executes
MACHINE CODE
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
COMPILER INTERPRETER
- spends longer with analysing and
- spends less time in analysing and
processing the program processing
- PyPy
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON - PYTHON INTERPRETER
high-level
SOURCE CODE SOURCE CODE *.py file
VIRTUAL
MACHINE
executes
instructions
MACHINE CODE
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
SOURCE CODE
print(„hello world“)
machine code.
SEQUENCE
01011001011100010
CPU
EXECUTABLES WITH PYTHON
Exercise:
Open https://interactivepython.org/runestone/static/CS152f17/
GeneralIntro/ThePythonProgrammingLanguage.html
Read the short text and make the little quiz below.
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON
Bytecode:
▸ Is an intermediate representation of your program.
▸ Is what the virtual machine sees of your program - it could described as the machine code
for your virtual machine.
▸ Is cached as .pyc file (for the CPython Interpreter) -> we can read the byte code with the
‚disassembler’ module.
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON
Machine Code:
▸ Is written in machine language instructions which can be executed directly by a CPU.
▸ Is strictly numerical.
▸ Is hardware dependent.
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON
Assembly:
▸ Uses mnemonic codes to refer to machine instructions.
Instruction Set:
▸ Every processor has its own instruction set.
Instruction:
▸ Instructions are patterns of bits corresponding to different commands of the machine.
▸ Instructions cause the CPU to perform specific tasks, like loading, jumping to a memory
address, performing operations on the ALU, or the registers.
▸ Most instructions have one or more opcode fields, specifying the basic instruction type
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
(jump, load, add etc.) and more fields for the addressing modes, actual value etc.
EXECUTABLES WITH PYTHON
Instruction types
https://en.wikipedia.org/wiki/Instruction_set_architecture#Instructions
EXECUTABLES WITH PYTHON
The Fetch-Decode-Execute-Cycle:
▸ https://www.hartismere.com/20398/CPU-Fetch-Decode-Execute-Animation
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON - PYTHON BYTECODE
Python’s disassemble module makes it possible to view the actual byte code in a
human readable form
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON - PYTHON BYTECODE
INSTRUCTION
operation
argument
name value
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON
Executables:
▸ Executables are programs that are developed for a specific platform or device.
▸ They have binary format and comply to the demands of the specific hardware architecture.
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
EXECUTABLES WITH PYTHON
- bbFreeze (https://pypi.org/project/bbfreeze/)
- PyInstaller (https://github.com/pyinstaller/pyinstaller/wiki/Supported-
Packages)
Windows only:
- Pynsist (https://pynsist.readthedocs.io/en/latest/)
- Py2exe (https://sourceforge.net/projects/py2exe/files/py2exe/)
Mac OS only:
MDM TECHNOLOGICAL BASICS II WS 2018/19 H.LINGOR
- Py2app (https://py2app.readthedocs.io/en/latest/)