无法执行发布升级,因为 which python 指向 env/bin/python

无法执行发布升级,因为 which python 指向 env/bin/python

我想将我的 Ubuntu 从 18.04.6 LTS 升级到 20.04.3 LTS,但是运行时出现错误do-release-upgrade

Cannot upgrade 

Your python3 install is corrupted. Please fix the '/usr/bin/python3' 
symlink.

我注意到,即使未激活,python 也会指向我的虚拟环境。

user@abc-lenovo-ideapad-710s-13isk$ which python
/home/user/python/env/bin/python

我的问题是如何让 python 指向/usr/bin/python3.9

这是我尝试过的:

sudo update-alternatives  --set python /usr/bin/python3.9     
update-alternatives: error: alternative /usr/bin/python3.9 for python not registered; not setting

此命令适用于 python3,但不幸的是它没有改变,which python仍然指向/home/bragar/python/env/bin/python

这是所有的 Python 二进制文件:

user@abc-lenovo-ideapad-710s-13isk:~$ ls /usr/bin/python*
/usr/bin/python     /usr/bin/python2.7-config  /usr/bin/python3.6         /usr/bin/python3.6m-config  /usr/bin/python3.9         /usr/bin/python3-jsonschema  /usr/bin/python-config
/usr/bin/python2    /usr/bin/python2-config    /usr/bin/python3.6-config  /usr/bin/python3.7          /usr/bin/python3.9-config  /usr/bin/python3m
/usr/bin/python2.7  /usr/bin/python3           /usr/bin/python3.6m        /usr/bin/python3.7m         /usr/bin/python3-config    /usr/bin/python3m-config

答案1

您必须从 PATH 环境变量中删除本地 python,然后使用以下命令运行升级过程:

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
sudo -E apt-get update
sudo -E apt-get dist-upgrade
sudo -E do-release-upgrade

相关内容