簡體   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