The Singularity
The Singularity

Reputation: 2698

Upgrading Python 3.7 to 3.9 on macOS Big Sur

I'm trying to upgrade Python 3.7 to 3.9 on macOS Big Sur. I'm also trying to avoid losing packages that were installed on Python 3.7 and reinstalling them again on Python 3.9

I tried using

brew install python3
brew update && brew upgrade python

which yielded

Already up-to-date.
Warning: python3 3.9.1_7 already installed

However when I run python3 --version it yields Python 3.7.0

Is this an issue with the alias? Is there a way to uninstall Python 3.7 and keep Python 3.9?

Running brew link python3 yields

Linking /usr/local/Cellar/[email protected]/3.9.1_7... 
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite --dry-run [email protected]

Upvotes: 2

Views: 22690

Answers (2)

storenth
storenth

Reputation: 1225

I suggest use official binaries:

  1. Download version you need from the python.org
  2. Call the .pkg
  3. Invoke Update Shell Profile.command script under /Applications/Python\ 3.XX/
  4. After all reboot your terminal
  5. Check your Python version. The old version and dependencies remain intact. enter image description here

Upvotes: 0

The Singularity
The Singularity

Reputation: 2698

I fixed this frustrating error by first removing the Python 3.7 manually, by deleting it from the Applications folder and then uninstalling Python 3.9 using brew uninstall python3

Next, I downloaded and installed the latest Python from here and it worked!

To save all the installed packages by generating a requirements file, Run

python3 -m pip freeze > requirements.txt

and to install them in another environment, Run

python3 -m pip install -r requirements.txt

Upvotes: 5

Related Questions