Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching Python version installed by Homebrew

I have Python 3.8 and 3.9 installed via Homebrew:

~ brew list | grep python
[email protected]
[email protected]

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/[email protected]/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?

like image 472
Robo Robok Avatar asked Oct 14 '20 23:10

Robo Robok


People also ask

Can I have multiple versions of Python installed on Mac?

pyenv is a Python version management tool. It allows you to install multiple versions of Python and easily switch between them. To install, follow these instructions (or see the full installation instructions on the official GitHub repository): Install using brew: brew install pyenv.

How do I downgrade to previous version of Python?

Use Anaconda Prompt to Downgrade Python on Windows This method is limited to the users of Anaconda Navigator. On the Anaconda prompt, we can install the required version of Python and overwrite the previous version using the conda install python= version command.

How to install Python on homebrew for Mac?

Since we will be using Homebrew manager to install our Python manager, here's a quick tutorial on how to install Homebrew for Mac users. pyenv is the python package manager. You will then want to configure your environmental variables and leave PyEnv to manage your packages. You can activate your changes by running.

How do I install pyenv through homebrew?

To install pyenv, use the following code in the command-line: Then find the name of the python version you want to switch to with this: In your case, it's most likely named 3.9.0. Why wouldn't I want to install pyenv through Homebrew? The script above does install through Homebrew and sets it up to launch pyenv on bootup.

How do I install a Python module in Brew?

For brewed Python, modules installed with pip3 or python3 setup.py install will be installed to the $ (brew --prefix)/lib/pythonX.Y/site-packages directory (explained above). Executable Python scripts will be in $ (brew --prefix)/bin. The system Python may not know which compiler flags to set in order to build bindings for software installed in ...

Is it possible to install Python side by side in homebrew?

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: Re-opening your terminal or execute command rehash can be required to take account the change. Thanks for answering.


2 Answers

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 [email protected]
brew unlink [email protected]
brew link --force [email protected]

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

like image 90
Jean-Pierre Matsumoto Avatar answered Oct 21 '22 20:10

Jean-Pierre Matsumoto


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.

like image 29
Seth Avatar answered Oct 21 '22 22:10

Seth