Reputation: 447
I am a beginner to python programming language. I have seen the definition "python is portable" at https://docs.python.org/.
Query 1: Python is portable - Does it mean python scripts or python executable??
Query 2: Like JVM, for Java, is anything needed to run "python executable" on target machine.
Upvotes: 0
Views: 2993
Reputation: 41784
Python is portable - Does it mean python scripts or python executable?
The Python script is portable because it runs on the Python Virtual Machine (PVM)
Python is basically an interpreted language. However Python implementations may compile source code to bytecode in order to reuse/optimize/whatever so in some sense/implementation Python is a compiled language
Python is an interpreted language, as opposed to a compiled one, though the distinction can be blurry because of the presence of the bytecode compiler. This means that source files can be run directly without explicitly creating an executable which is then run.
Like JVM, the PVM is an abstract machine that runs on the current computer so we needs a PVM implementation for each platform which means the Python executor is not portable, but the compiled code (*.pyc) is portable, like the Python script
However currently it's even possible to have a portable PVM. Just a single executable can run on Linux, Mac, Windows, NetBSD, FreeBSD, OpenBSD because of the great αcτµαlly pδrταblε εxεcµταblε (APE) project so one can distribute their work easily by providing a small Python executable (which is just more than 4MB at the moment) along with a *.py file
See Python is Actually Portable
See also
Upvotes: 0
Reputation: 46
Most probably you will have read somewhere that the Python language is an interpreted programming or a script language. The truth is: Python is both an interpreted and a compiled language. But calling Python a compiled language would be misleading. People would assume that the compiler translates the Python code into machine language but this is not the way python code is executed. Python code is translated into intermediate code, which has to be executed by a virtual machine, known as the PVM, the Python virtual machine. This is a similar approach to the one taken by Java. There is even a way of translating Python programs into Java byte code for the Java Virtual Machine (JVM). This can be achieved with Jython. The default implementation of python is Cython but there is more like Jython, PyPy,IronPython and more!
Upvotes: 3