Python解释器与全局环境之间的关系是什么?

huangapple go评论73阅读模式
英文:

What is the relationship between a python interpreter and a global environment

问题

有很多好文章解释为什么要使用 Python 虚拟环境。但我找不到的信息是在我的机器上是有一个全局环境,还是每个主要版本的 Python(例如一个用于 Python 2,一个用于 Python 3),每个版本一个(一个用于 3.9,一个用于 3.10,...),甚至更细粒度的情况下,一个全局环境用于 3.9.7,一个用于 3.9.8,...。我只是想弄清楚“全局”一词是如何应用的。

谢谢。

英文:

There are a lot of good articles explaining why you should use python virtual environments. But what I am not able to find out is whether there is one global environment on my machine, or one per major version of python (e.g. one for python 2 and one for python 3), one per version (one for 3.9, one for 3.10, ...), or even more granular and one global environment for 3.9.7, one for 3.9.8, ... . I just want to understand what context the word "global" is being applied to.

Thank you.

答案1

得分: 1

"Global" 不是一个官方术语,所以我只能猜测这些好文章是什么意思。我猜想它是特定 Python 版本的安装。因此,确实可以有 3.9.7 和 3.9.8 的全局环境。

至于在计算机上找到它们的位置,Windows 有 py 启动器,可以列出它们。其他平台可能也有类似的东西。

py -0

通过 py 启动器找到的已安装的 Python

-3.9-64 *

-2.7-64

正如你所看到的,我安装了 2 个版本的 Python。我认为这就是你所称之为 "全局环境" 的东西。

英文:

"Global" is not an official term, so I can only guess what these good articles mean by it. My guess is, it's an installation of a particular Python version. So, indeed, you could have 3.9.7 and 3.9.8 global environments.

As for where you can find them on your computer, Windows has the py launcher, which can list them. Other platforms might have something like that too.

> py -0
>
> Installed Pythons found by py Launcher for Windows
>
> -3.9-64 *
>
> -2.7-64

As you see, I have 2 versions of Python installed. I think these are what you call "global environments".

答案2

得分: 0

解释器只是Python环境的一个部分,库是另一个部分。

库本身可以分为两部分:标准库,由语言定义,需要存在于任何环境中;以及一组站点包,最初为空,但可以由环境的维护者添加和删除。

全局环境实际上只是一个独立的Python安装。虚拟环境基本上只是解释器和某个全局环境的标准库(可以视为不可变和只读)与一组私有站点包之间的链接。

英文:

The interpreter is just one part of any Python environment, the library being the other part.

The library itself can be split into two parts: the standard library, defined by the language and required to be present in any environment, and a collection of site packages, which is initially empty but can be added to and deleted from by the maintainer of an environment.

A global environment is really just a standalone Python installation. A virtual environment is basically just a link between the interpreter and standard library (which can be considered immutable and read-only) of some global environment and a private set of site packages.

huangapple
  • 本文由 发表于 2023年7月23日 20:31:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76748246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定