MacOS:如何降级自制Python? [英] MacOS: How to downgrade homebrew Python?

查看:127
本文介绍了MacOS:如何降级自制Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行MacOS Sierra 10.12.4,并且我已经意识到自制python已升级到2.7.13版.如何切换回2.7.10?

I'm running MacOS Sierra 10.12.4 and I've realized that homebrew python was upgraded to version 2.7.13. How can I switch back to 2.7.10?

推荐答案

首先,如果可以避免的话,通常将系统python用作用户登陆代码是不明智的做法.您需要假设系统实用程序需要特定版本的系统python,然后您的用户登陆代码可能会永远锁定到该python版本,这是不明智的(除非您正在编写系统实用程序,在这种情况下,只需使用/bin/python,但您不会问这个问题...).

First, it's generally considered bad practice to rely on system python for user land code if you can avoid it. You need to assume that system utilities require a specific version of system python, and your user land code may then be locked to that python version forever, which is not wise (unless you're writing system utilities, in which case just use /bin/python, but then you wouldn't be asking this question...).

第二,我不清楚为什么您需要2.7.10而不是2.7.13.具有相同次要修订号(2.7)的所有python应该始终兼容.如果您需要2.6,那将是另一回事,因为这是次要版本中的更改.为2.7.x编写的代码应该全部兼容.

Secondly, I am unclear why you need 2.7.10 instead of 2.7.13. All pythons with the same minor revision number (2.7) should always be compatible. If you needed 2.6, that would be a different story since that's a change in minor version. Code written for 2.7.x should all be compatible.

但是,假设您的用例确实需要使用特定的Python版本-立即获取实际解决方案-请确保您确实从一开始就升级了系统python.如果输入命令:which python,是否得到/usr/bin/python(系统)或/usr/local/bin/python(棕色已安装的用户级python).例如,/usr/bin/python -V给我2.7.10,即使python -V给我2.7.13(通过brew).

However, assuming your use case really does require using a specific Python version - getting to an actual solution now - be sure sure you really upgraded system python to begin with. If you enter the command: which python, do you get /usr/bin/python (system) or /usr/local/bin/python (brew installed user-land python). For example, /usr/bin/python -V gives me 2.7.10 even though python -V gives me 2.7.13 (via brew).

可能是通过brew安装了最新的python 2.7.x,将/usr/local/bin/python作为符号链接放置在$PATH中,或者您可能有python别名指向了不需要的位置.验证您的$ PATH订单.

It's possible that you installed the latest python 2.7.x via brew which puts /usr/local/bin/python as a symlink in your $PATH, or you perhaps have a python alias pointing somewhere you don't want. Verify your $PATH order.

您可以通过删除(brew uninstall python)或更改符号链接(ln -s -f /usr/bin/python /usr/local/bin/python)来重置自制python.但是,使用virtualenv消除了对许多这类体操的需求.

You can reset your homebrew python by removing it (brew uninstall python), or by changing the symlink (ln -s -f /usr/bin/python /usr/local/bin/python). However, using virtualenv removes the need for much of these sorts of gymnastics.

如果您想了解通过自制程序安装的Python的早期版本,此答案应该会有所帮助:

If you want to monkey with prior versions of Python installed via homebrew, this answer should help: How to install older formula using Brew?

最后一个选择:如果您绝对必须具有特定的python版本,则 pyenv 可以提供帮助.

One final option: if you absolutely must have a specific python version, pyenv can help.

brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10

这篇关于MacOS:如何降级自制Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆