Switching Python version installed by Homebrew

社会主义新天地 提交于 2021-01-18 04:49:36

问题


I have Python 3.8 and 3.9 installed via Homebrew:

~ brew list | grep python
python@3.8
python@3.9

I want to use Python 3.9 as my default one with python3 command. I tried the following:

~ brew switch python 3.9
Error: python does not have a version "3.9" in the Cellar.
python's installed versions: 3.8.6

I tried to uninstall Python and reinstall it, but it's used by other packages:

~ brew uninstall python
Error: Refusing to uninstall /usr/local/Cellar/python@3.8/3.8.6
because it is required by glib and php, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python

How can I use Python 3.9?


回答1:


There is an Homebrew known issue related to side by side install of Python 3.8 / 3.9. To workaround, following commands should work for you:

brew unlink python@3.9
brew unlink python@3.8
brew link --force python@3.9

Re-opening your terminal or execute command rehash can be required to take account the change.




回答2:


Use pyenv. It's a software that lets you switch between any and all Python versions installed on your system. To install pyenv, use the following code in the command-line:

curl https://pyenv.run | bash
exec $SHELL

Then find the name of the python version you want to switch to with this:

pyenv versions

And select it with this:

pyenv global <version-name>

In your case, it's most likely named 3.9.0.



来源:https://stackoverflow.com/questions/64362772/switching-python-version-installed-by-homebrew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!