简体   繁体   English

python 程序/可执行文件是否可移植?

[英]Is python program/executable portable?

I am a beginner to python programming language.我是 python 编程语言的初学者。 I have seen the definition "python is portable" at https://docs.python.org/ .我在https://docs.python.org/看到了“python 是可移植的”的定义。

Query 1: Python is portable - Does it mean python scripts or python executable??查询 1: Python 是可移植的 - 这是否意味着 python 脚本或 python 可执行文件?

Query 2: Like JVM, for Java, is anything needed to run " python executable " on target machine.查询 2:像 JVM 一样,对于 Java,是否需要在目标机器上运行“ python 可执行文件”。

Most probably you will have read somewhere that the Python language is an interpreted programming or a script language.您很可能在某处读到 Python 语言是一种解释性编程或脚本语言。 The truth is: Python is both an interpreted and a compiled language.事实是:Python 既是一种解释型语言,又是一种编译型语言。 But calling Python a compiled language would be misleading.但是将 Python 称为编译语言会产生误导。 People would assume that the compiler translates the Python code into machine language but this is not the way python code is executed.人们会假设编译器将 Python 代码翻译成机器语言,但这不是 Python 代码的执行方式。 Python code is translated into intermediate code, which has to be executed by a virtual machine, known as the PVM, the Python virtual machine. Python 代码被翻译成中间代码,它必须由一个虚拟机执行,称为 PVM,即 Python 虚拟机。 This is a similar approach to the one taken by Java.这是一种类似于 Java 所采用的方法。 There is even a way of translating Python programs into Java byte code for the Java Virtual Machine (JVM).甚至有一种方法可以将 Python 程序转换为 Java 虚拟机 (JVM) 的 Java 字节码。 This can be achieved with Jython.这可以通过 Jython 实现。 The default implementation of python is Cython but there is more like Jython, PyPy,IronPython and more! python 的默认实现是 Cython,但还有更多像 Jython、PyPy、IronPython 等等!

Python is portable - Does it mean python scripts or python executable? Python 是可移植的 - 这是否意味着 python 脚本或 python 可执行文件?

The Python script is portable because it runs on the Python Virtual Machine (PVM) Python 脚本是可移植的,因为它在Python 虚拟机 (PVM)上运行

Python is basically an interpreted language. Python基本上是一种解释语言。 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 实现可以将源代码编译为字节码,以便在某种意义上重用/优化/无论如何/实现 Python 是一种编译语言

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. Python 是一种解释语言,而不是编译语言,尽管由于字节码编译器的存在,区别可能很模糊。 This means that source files can be run directly without explicitly creating an executable which is then run.这意味着可以直接运行源文件,而无需显式创建随后运行的可执行文件。

https://docs.python.org/3/glossary.html#term-interpreted https://docs.python.org/3/glossary.html#term-interpreted

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 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 .然而,目前甚至可以拥有便携式 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 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时刻)以及一个 *.py 文件

See Python is Actually Portable请参阅Python 实际上是便携式的


See also也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM