簡體   English   中英

啟動 python 解釋器時顯示的消息的含義

[英]Meaning of the message displayed when starting the python interpreter

我知道這肯定是基本信息或知識,但我想知道(並且找不到答案)在執行python命令並啟動解釋器之后顯示的含義或信息是什么?

例如,在這種情況下這意味着什么?:

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32

輸入“help”、“copyright”、“credits”或“license()”以獲取更多信息。

>>>

我知道這是每次你在命令行上啟動解釋器時都會看到的東西,也許是人們忽略的東西,但現在它讓我想知道。

讓我們看一下Python 的源代碼,看看它是如何生成該消息的。 因為如果一切都失敗了,你可以看看源代碼。

如果我們搜索Type "help", "copyright", "credits" or "license()" for more information. ,其中一個結果在Modules/main.c

#define COPYRIGHT \
    "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
    "for more information."

如果我們查看它的使用位置,我們可以看到它在pymain_header function 中——相關代碼如下:

fprintf(stderr, "Python %s on %s\n", Py_GetVersion(), Py_GetPlatform());
    if (config->site_import) {
        fprintf(stderr, "%s\n", COPYRIGHT);
    }

所以,現在我們需要看看Py_GetVersion()Py_GetPlatform()做了什么。

Py_GetVersion執行以下操作:

static char version[250];
    PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
                  PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
    return version;

所以,現在我們需要看看Py_GetBuildInfo()Py_GetCompiler()做了什么。 PY_VERSION是 Python 的版本。

Py_GetBuildInfo()的相關部分是:

PyOS_snprintf(buildinfo, sizeof(buildinfo),
                  "%s%s%s, %.20s, %.9s", gitid, sep, revision,
                  DATE, TIME);

Inferring from the rest of the code, and the build configuration , gitid is either the git tag of the current Python version, or if that doesn't exist, the git branch. sep只是一個分隔符, revision是 python 源的HEAD提交的短 sha-1 hash。 我假設DATETIME是構建的日期和時間。

Py_GetCompiler的來源表明它輸出[Clang __clang_version__][GCC __VERSION__][C++][C]或其他內容(例如[MSC]以及 MSC 版本),具體取決於編譯 Python 的內容。

最后,查看Py_GetPlatform()的代碼,它正在獲取當前 Python 構建的平台。 可能的值似乎包括win32 ,但我不確定其他值是什么,但我認為它指的是特定的 Mac 和 Linux 操作系統版本等。

因此,將所有這些信息收集在一起,細分如下:

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit (AMD64)] on win32

  • Python
  • 3.8.7 :Python版本
  • (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) : (git branch or tag name:git revision short sha-1, build date, build time)
  • [MSC v.1928 64 位 (AMD64)] : [編譯器名稱和版本]
  • win32 : 平台名稱

好的,讓我們看一下消息的每個部分。

  • Python 3.8.7 - python 的版本(顯然)
  • tags/v3.8.7:6503f05 - python repo 的 github 標簽。 如果你要 go 到 github 上的這個標簽並查看最新提交,你會發現提交 ID 是6503f05
  • Dec 21 2020, 17:59:51 - 此提交的發布日期。 再次檢查標簽並查看最新提交是在此日期。
  • MSC v.1928 - Microsoft C 編譯器和版本。
  • 64 bit (AMD64) - 64 位告訴我們這個 python 是 64 位。 有關 32 位和 64 位的更多說明,請參閱此答案
  • on win32 - windows 的操作系統信息。 這是 32 位 windows。 我建議安裝 32 位 python 版本,因為您當前擁有的 64 位 python 不是為 win32 構建的。

參考:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM