在 macOS Big Sur 上将 Python 3.7 升级到 3.9

Luk*_*uke 2 python

我正在尝试在 macOS Big Sur 上将 Python 3.7 升级到 3.9。我还试图避免丢失在 Python 3.7 上安装的包并在 Python 3.9 上再次重新安装它们

我尝试使用

brew install python3
brew update && brew upgrade python
Run Code Online (Sandbox Code Playgroud)

这产生了

Already up-to-date.
Warning: python3 3.9.1_7 already installed
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时python3 --version它会产生Python 3.7.0

这是别名的问题吗?有没有办法卸载Python 3.7并保留Python 3.9?

运行brew link python3产量

Linking /usr/local/Cellar/python@3.9/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 python@3.9

To list all files that would be deleted:
  brew link --overwrite --dry-run python@3.9
Run Code Online (Sandbox Code Playgroud)

Luk*_*uke 5

我修复了这个令人沮丧的错误,首先手动删除 Python 3.7,从Applications文件夹中删除它,然后使用卸载 Python 3.9brew uninstall python3

接下来,我从这里下载并安装了最新的Python,它成功了!

要通过生成需求文件来保存所有已安装的软件包,请运行

python3 -m pip freeze > requirements.txt
Run Code Online (Sandbox Code Playgroud)

并将它们安装在另一个环境中,运行

python3 -m pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)