【问题标题】:Upgrading Python 3.7 to 3.9 on macOS Big Sur在 macOS Big Sur 上将 Python 3.7 升级到 3.9
【发布时间】:2021-05-06 07:21:56
【问题描述】:

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

我尝试过使用

brew install python3
brew update && brew upgrade python

产生了

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

但是,当我运行 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

【问题讨论】:

  • 听起来你的PATH 是错误的。 type -a python3 的输出是什么?你的PATH 是什么样的,你是从你的shell 的启动文件中操作它吗?请edit提供这些详细信息。
  • 没有办法让所有已安装的软件包都随身携带。 pip 的体系结构要求您将所需的包安装到所需的 Python 版本中。您可以在旧 Python 中运行 pip freeze,然后(可能手动修剪列表和)pip install 相同的包到新版本中。

标签: python


【解决方案1】:

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

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

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

python3 -m pip freeze > requirements.txt

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

python3 -m pip install -r requirements.txt

【讨论】:

    猜你喜欢
    • 2021-02-28
    • 2021-07-23
    • 2021-03-03
    • 2021-05-08
    • 2021-02-27
    • 1970-01-01
    • 2021-06-19
    • 2021-08-04
    • 2021-05-31
    相关资源
    最近更新 更多