Python 如何使用 Brew 安装旧配方?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32699057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:06:00  来源:igfitidea点击:

How to install older formula using Brew?

pythonhomebrew

提问by swdev

Using the case of installing Python 2.7.9 instead of the latest 2.7.10, previously I could simply use brew versions pythonand see all of the versions of Python formulae by their commit SHA in brew, and then check them out to install a specific version. This is an example of brew versions pythonoutput:

使用安装 Python 2.7.9 而不是最新的 2.7.10 的情况,以前我可以brew versions python通过它们在 brew 中的提交 SHA来简单地使用和查看 Python 公式的所有版本,然后检查它们以安装特定版本。这是一个brew versions python输出示例:

$ brew versions python
Warning: brew-versions is unsupported and will be removed soon.
You should use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions
2.7.9    git checkout 667284f /usr/local/Library/Formula/python.rb
2.7.8    git checkout f26ca5c /usr/local/Library/Formula/python.rb
2.7.7    git checkout d48206e /usr/local/Library/Formula/python.rb
2.7.6    git checkout 3c64184 /usr/local/Library/Formula/python.rb
2.7.5    git checkout a04b443 /usr/local/Library/Formula/python.rb
2.7.3    git checkout 865f763 /usr/local/Library/Formula/python.rb
2.7.4    git checkout 280581d /usr/local/Library/Formula/python.rb
2.7.2    git checkout 97c6869 /usr/local/Library/Formula/python.rb
2.7.1    git checkout 83ed494 /usr/local/Library/Formula/python.rb
2.7      git checkout 1bf3552 /usr/local/Library/Formula/python.rb
2.6.5    git checkout acd49f7 /usr/local/Library/Formula/python.rb
2.6.4    git checkout 843bff9 /usr/local/Library/Formula/python.rb
2.6.3    git checkout 5c6cc64 /usr/local/Library/Formula/python.rb

But the latest version of brew has already removed versionssupport, and I don't understand how to install a previous Python using https://github.com/Homebrew/homebrew-versions. How do you actually install Python 2.7.9 instead of the newer 2.7.10?

但是最新版本的 brew 已经取消了versions支持,我不明白如何使用https://github.com/Homebrew/homebrew-versions安装以前的 Python 。您如何实际安装 Python 2.7.9 而不是较新的 2.7.10?

I would like to know how to use homebrew-versionsinstead of the more trivial way brew versions.

我想知道如何使用homebrew-versions而不是更琐碎的方式brew versions

With brew versionsI could easily see all versions from that specific formulae (have a look at the above Python versions spit out by brew versions python). From the doc, there is no clear way to achieve the same result as brew versions pythondoes.

随着brew versions我可以很容易地看到从该特定公式的所有版本(看看上面的Python版本吐出的brew versions python)。从doc来看,没有明确的方法可以达到相同的结果brew versions python

采纳答案by Vincent Cunningham

homebrew-versions used to be the easiest way to do this, but homebrew-versions has been deprecated and is no longer available in the current version of homebrew.

homebrew-versions 曾经是执行此操作的最简单方法,但 homebrew-versions 已被弃用并且在当前版本的 homebrew 中不再可用。

To find what versions are readily available, use the following command:

要查找随时可用的版本,请使用以下命令:

brew search python

to list out all of the available python packages which would display old versions like python@2and then you could install them by using:

列出所有可用的python包,这些包将显示旧版本python@2,然后您可以使用以下方法安装它们:

brew install python@2

Some Alternative Approaches

一些替代方法

Switching To Previous Version

切换到以前的版本

If you have already installed the older version of the formula and have not removed it you can simply switch the symlinks to reference it using a brew command.

如果您已经安装了旧版本的公式并且没有删除它,您可以简单地切换符号链接以使用 brew 命令引用它。

brew switch python 2.7.9

This command would switch you to version 2.7.9

此命令会将您切换到版本 2.7.9

brew switch python 2.7.10

This would switch you back to version 2.7.10

这会将您切换回 2.7.10 版

Formula GitHub History

公式 GitHub 历史

If you do not still have the older version available on your system there is another method you could try but it is more difficult and almost certainly unsupported by Homebrew so if you end up with issues you may not be able to rely on their help.

如果您的系统上仍然没有旧版本,您可以尝试另一种方法,但它更困难,而且几乎肯定不受 Homebrew 支持,因此如果您最终遇到问题,您可能无法依赖他们的帮助。

https://github.com/Homebrew/homebrew-core/commits/master/Formul/<formula>.rbshould take you to the commit history of that formula. For your example of installing python 2.7.9 you would do the following:

https://github.com/Homebrew/homebrew-core/commits/master/Formul/<formula>.rb应该带你到那个公式的提交历史。对于安装 python 2.7.9 的示例,您将执行以下操作:

  1. Go to https://github.com/Homebrew/homebrew-core/commits/master/Formula/python.rb
  2. Look for the entry with a commit summary of "python 2.7.10"
  3. Find and copy the commit hash of the entry below it (1681e19in this example)
  4. Input git checkout 1681e19 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rbinto the terminal
  1. https://github.com/Homebrew/homebrew-core/commits/master/Formula/python.rb
  2. 查找提交摘要为“python 2.7.10”的条目
  3. 查找并复制其下方条目的提交哈希(1681e19在此示例中)
  4. 输入git checkout 1681e19 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/python.rb到终端

From this point you would do whatever you would normally do to install the older version of python with the old versions method. This appears to be all the old method was doing.

从这一点开始,您可以做任何您通常会使用旧版本方法安装旧版本 python 的操作。这似乎是所有旧方法所做的。

回答by Tim Smith

Homebrew doesn't support installing formulas from git history, although it's possible. There are no python* formulas in the homebrew-versions tap because I think they would be a lot of work to maintain and don't provide the best possible user experience. pyenvis a great tool that solves a lot of the problems associated with keeping multiple pythons around. There's also a user-maintained tapwith older Python versions; you could contribute a 2.7.9 formula there.

Homebrew 不支持从 git 历史记录安装公式,尽管它是可能的。homebrew-versions tap 中没有 python* 公式,因为我认为它们需要大量的维护工作并且不能提供最佳的用户体验。pyenv是一个很好的工具,它解决了许多与保持多个python相关的问题。还有一个用户维护的带有旧 Python 版本的水龙头;你可以在那里贡献一个 2.7.9 公式。