3.4.4.2. 自定义默认的Python版本¶
In some cases, a version qualifier can be included in a command to dictate
which version of Python will be used by the command. A version qualifier
starts with a major version number and can optionally be followed by a period
(‘.’) and a minor version specifier. If the minor qualifier is specified, it
may optionally be followed by “-32” to indicate the 32-bit implementation of
that version be used.
例如,一个shebang line 的 #!python 行没有版本限定符,而 #!python3 有一个版本限定符,它只指定一个主要版本。
If no version qualifiers are found in a command, the environment variable
PY_PYTHON can be set to specify the default version qualifier - the default
value is “2”. Note this value could specify just a major version (e.g. “2”) or
a major.minor qualifier (e.g. “2.6”), or even major.minor-32.
如果没有找到次要版本限定符,则可以设置环境变量 PY_PYTHON{major} (其中 {major} 是上面确定的当前主要版本限定符)以指定完整版本。如果没有找到这样的选项,启动器将枚举已安装的Python版本并使用为主要版本找到的最新次要版本,尽管不能保证,但该版本可能是该系列中最新安装的版本。
On 64-bit Windows with both 32-bit and 64-bit implementations of the same
(major.minor) Python version installed, the 64-bit version will always be
preferred. This will be true for both 32-bit and 64-bit implementations of the
launcher - a 32-bit launcher will prefer to execute a 64-bit Python installation
of the specified version if available. This is so the behavior of the launcher
can be predicted knowing only what versions are installed on the PC and
without regard to the order in which they were installed (i.e., without knowing
whether a 32 or 64-bit version of Python and corresponding launcher was
installed last). As noted above, an optional “-32” suffix can be used on a
version specifier to change this behaviour.
示例:
如果没有设置相关选项,命令 python 和 python2 将使用安装的最新Python 2.x版本,命令 python3 将使用最新安装的Python 3.x.
命令 python3.1 和 python2.7 根本不会查阅任何选项,因为版本已完全指定。
如果 PY_PYTHON=3 ,命令``python`` 和 python3 都将使用最新安装的Python 3版本。
如果 PY_PYTHON=3.1-32 ,命令 python 将使用3.1的32位实现,而命令 python3 将使用最新安装的Python(PY_PYTHON根本没有被视为指定了主要版本。)
如果 PY_PYTHON=3 且 PY_PYTHON3=3.1,命令 python 和 python3 都将特别使用3.1
除环境变量外,还可以在启动程序使用的.INI文件中配置相同的设置。 INI文件中的部分称为 [defaults] ,键名称将与没有前导 PY_ 前缀的环境变量相同(并注意INI文件中的键名不区分大小写) 。)环境变量的内容将覆盖INI文件中指定的内容。
例如:
设置 PY_PYTHON=3.1 等同于包含以下内容的INI文件:
[defaults]
python=3.1
设置 PY_PYTHON=3 和 PY_PYTHON3=3.1 相当于包含以下内容的INI文件:
[defaults]
python=3
python3=3.1