如何从Ubuntu19.10卸载Python3.7?

2024-03-28 11:59:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是Ubuntu 19.10,其中有版本为3.7的python。在我安装的python 3.8发布后,现在我想卸载python 3.7,这样每当我在终端中调用python3时,它总是调用{}?在


Tags: 版本终端ubuntupython3
3条回答

我建议你不要碰默认的OS python安装。系统的其他部分可能依赖于它,没有办法知道升级是否会破坏某些东西,即使它不应该。在

我还建议您学习(如果您还没有,但我想您没有,因为这个问题)使用python虚拟环境,比如virtualenv。这允许您为您编写的每个项目设置特定的python环境。这意味着每个环境都可以有自己的python版本,除了该版本的标准python库之外,还可以为该项目使用pip安装任何其他第三方python库。这将项目彼此隔离。你不会因为另一个的升级而破坏一个。在

也就是说,如果您想保持Python版本的先进性,可以从源代码进行安装,然后使用altinstall参数将其安装到系统中(请参见自述文件.rstPython发行版的。这样,所有安装的版本都可以使用不同的名称(pip的名称相同),然后使用所需的版本创建每个虚拟环境。virtualenv有一个参数,可以根据需要应用特定(旧)版本。在

引用“安装多个版本”部分的自述:

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix ( prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using make altinstall contain the major and minor version and can thus live side-by-side. make install also creates ${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using make install. Install all other versions using make altinstall. For example, if you want to install Python 2.7, 3.6, and 3.8 with 3.8 being the primary version, you would execute make install in your 3.8 build directory and make altinstall in the others.

最后,如果你还想做的话,其他答案也可以。在

so that whenever I would call python3 in my terminal, it would always call python3.8

您只需在/home路径中的.bashrc文件中为python3.8创建一个别名。在

用您喜欢的编辑器打开~/.bashrc,然后转到最后一行。在

附加此行:

alias python='python3.8'

每当您在终端中调用python,它就会打开Python 3.8。在

注意:在创建具有特定版本的虚拟环境时,此操作无法按预期工作。你应该记住这一点。在

您不需要为此卸载旧版本。 您需要更新您的替代更新,然后您就可以设置默认的python版本。在

sudo update-alternatives  install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives  install /usr/bin/python python /usr/bin/python3.6 2

然后运行:

^{pr2}$

或者使用以下命令将python3.6设置为默认值:

sudo更新选项集python/usr/bin/python3.6 这应该行。在

相关问题 更多 >