繁体   English   中英

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

[英]Is python program/executable portable?

我是 python 编程语言的初学者。 我在https://docs.python.org/看到了“python 是可移植的”的定义。

查询 1: Python 是可移植的 - 这是否意味着 python 脚本或 python 可执行文件?

查询 2:像 JVM 一样,对于 Java,是否需要在目标机器上运行“ python 可执行文件”。

您很可能在某处读到 Python 语言是一种解释性编程或脚本语言。 事实是:Python 既是一种解释型语言,又是一种编译型语言。 但是将 Python 称为编译语言会产生误导。 人们会假设编译器将 Python 代码翻译成机器语言,但这不是 Python 代码的执行方式。 Python 代码被翻译成中间代码,它必须由一个虚拟机执行,称为 PVM,即 Python 虚拟机。 这是一种类似于 Java 所采用的方法。 甚至有一种方法可以将 Python 程序转换为 Java 虚拟机 (JVM) 的 Java 字节码。 这可以通过 Jython 实现。 python 的默认实现是 Cython,但还有更多像 Jython、PyPy、IronPython 等等!

Python 是可移植的 - 这是否意味着 python 脚本或 python 可执行文件?

Python 脚本是可移植的,因为它在Python 虚拟机 (PVM)上运行

Python基本上是一种解释语言。 然而 Python 实现可以将源代码编译为字节码,以便在某种意义上重用/优化/无论如何/实现 Python 是一种编译语言

Python 是一种解释语言,而不是编译语言,尽管由于字节码编译器的存在,区别可能很模糊。 这意味着可以直接运行源文件,而无需显式创建随后运行的可执行文件。

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


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

请参阅Python 实际上是便携式的


也可以看看

暂无
暂无

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

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