简体   繁体   English

为什么我应该将 Python 包安装到 `~/.local` 中?

[英]Why should I install Python packages into `~/.local`?

Background背景

  1. I don't develop using OS X's system provided Python versions (on OS X 10.6 that's Python 2.5.4 and 2.6.1).我不使用 OS X 系统提供的 Python 版本进行开发(在 OS X 10.6 上,即 Python 2.5.4 和 2.6.1)。
  2. I don't install anything in the site-packages directory for the OS provided versions of Python.对于操作系统提供的 Python 版本,我没有在 site-packages 目录中安装任何东西。 (The only exception is Mercurial installed from a binary package, which installs two packages in the Python 2.6.1 site-packages directory.) (唯一的例外是从二进制包安装 Mercurial,它会在 Python 2.6.1 站点包目录中安装两个包。)
  3. I installed three versions of Python, all using the Mac OS X installer disk image:我安装了三个版本的 Python,都使用 Mac OS X 安装程序磁盘映像:
    1. Python 2.6.6蟒蛇 2.6.6
    2. Python 2.7蟒蛇 2.7
    3. Python 3.1.2蟒蛇 3.1.2
  4. I don't like polluting the site-packages directory for my Python installations.我不喜欢污染我的 Python 安装的 site-packages 目录。 So I only install the following five base packages in the site-packages directory.所以我只在site-packages目录下安装了以下五个基础包。 For the actual method/commands used to install these, see SO Question 4324558 .有关用于安装这些的实际方法/命令,请参阅SO Question 4324558
    1. setuptools/ez_setup设置工具/ez_setup
    2. distribute分发
    3. pip点子
    4. virtualenv虚拟环境
    5. virtualenvwrapper虚拟包装器
  5. All other packages are installed in virtualenvs.所有其他软件包都安装在 virtualenvs 中。
  6. I am the only user of this MacBook.我是这台 MacBook 的唯一用户。

Questions问题

  1. Given the above background, why should I install the five base packages in ~/.local ?鉴于上述背景,我为什么要在~/.local安装五个基本包? Since I'm installing these base packages into the site-packages directories of Python distributions that I've installed, I'm isolated from the OS X's Python distributions.由于我将这些基本包安装到我已安装的 Python 发行版的 site-packages 目录中,因此我与 OS X 的 Python 发行版隔离。
  2. Using this method, should I be concerned about Glyph's comment that other things could potentially break (see his comment below)?使用这种方法,我是否应该关注 Glyph 的评论,即其他事情可能会破坏(请参阅下面的评论)?

Again, I'm only interested in where to install those five base packages.同样,我只对安装这五个基本软件包的位置感兴趣。

Related Questions/Info相关问题/信息

I'm asking because of Glyph 's comment to my answer to SO question 4314376 , which stated:我问是因为GlyphSO 问题 4314376 的回答的评论,其中指出:

NO.否。 NEVER EVER do sudo python setup.py install whatever.永远不要做sudo python setup.py install什么的。 Write a ~/.pydistutils.cfg that puts your pip installation into ~/.local or something.编写一个 ~/.pydistutils.cfg 将您的 pip 安装放入 ~/.local 或其他东西。 Especially files named ez_setup.py tend to suck down newer versions of things like setuptools and easy_install, which can potentially break other things on your operating system.特别是名为ez_setup.py文件往往会吸收更新版本的东西,比如 setuptools 和 easy_install,这可能会破坏操作系统上的其他东西。

Previously, I asked What's the proper way to install pip, virtualenv, and distribute for Python?之前,我问过为 Python 安装 pip、virtualenv 和分发的正确方法是什么? . . However, no one answered the "why" of using ~/.local .但是,没有人回答使用~/.local的“原因”。

There's no particularly good reason for or against installing in .local for Mac OS X installations using framework builds.对于使用框架构建的 Mac OS X 安装,没有特别好的理由支持或反对在.local中安装。 There is still some controversy among Python core developers on this point with Glyph arguing that the .local location, introduced in Python 2.6 for other Unixy systems, should be used for Mac OS X and simplifies third-party installation processes, while others argue that the previous traditional locations for Mac OS X framework builds is more natural. Python 核心开发人员在这一点上仍然存在一些争议,Glyph 认为在 Python 2.6 中为其他Unixy系统引入的.local位置应该用于 Mac OS X 并简化第三方安装过程,而其他人则认为以前的传统位置为 Mac OS X 框架构建更自然。 In the end, it is up to you.最后,这取决于你。 Particularly if you are using virtual environments, if it works, don't worry about it.特别是如果您正在使用虚拟环境,如果它有效,请不要担心。

As of 2020, I do not think it is a good idea to install Python packages into .local , but to use virtualenv to create a separate environment for each package.截至 2020 年,我认为将 Python 包安装到.local不是一个好主意,而是使用virtualenv为每个包创建单独的环境。

My reason我的理由

While installations into .local do not interfere with the system wide Python, you still can have conflicts between several packages installed into .local .虽然安装到.local不会干扰系统范围的 Python,但安装到.local几个包之间仍然可能存在冲突。

PS: If you do you like virtualenv you could also use pipx . PS:如果你喜欢virtualenv你也可以使用pipx

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

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