Ubuntu,你如何删除所有的 Python 3 而不是 2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34198892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ubuntu, how do you remove all Python 3 but not 2
提问by Wai Tong
I have recently get hold of a RackSpace Ubuntu server and it has pythons all over the place:
我最近拿到了一个 RackSpace Ubuntu 服务器,它到处都有 python:
iPython in 3.5, Pandas in 3.4 &2.7, modules I need like pyodbc etc. are only in 2,7
3.5 中的 iPython,3.4 和 2.7 中的 Pandas,我需要的模块(如 pyodbc 等)仅在 2,7 中
Therefore, I am keen to clean up the box and, as a 2.7 users, keep everything in 2.7.
因此,我热衷于清理盒子,作为 2.7 用户,将所有内容保留在 2.7 中。
So the key question is, is there a way to remove both 3.4 and 3.5 efficiently at the same time while keeping Python 2.7?
所以关键问题是,有没有办法在保留 Python 2.7 的同时有效地同时删除 3.4 和 3.5?
采纳答案by Wai Tong
So I worked out at the end that you cannot uninstall 3.4 as it is default on Ubuntu.
所以我最后发现你不能卸载 3.4,因为它是 Ubuntu 上的默认值。
All I did was simply remove Jupyter
and then alias python=python2.7
and install all packages on Python 2.7 again.
我所做的只是删除Jupyter
然后别名python=python2.7
并再次在 Python 2.7 上安装所有包。
Arguably, I can install virtualenv
but me and my colleagues are only using 2.7. I am just going to be lazy in this case :)
可以说,我可以安装,virtualenv
但我和我的同事只使用 2.7。在这种情况下,我只是懒惰:)
回答by Germain
EDIT:As pointed out in recent comments, this solution may BREAKyour system.
编辑:正如最近评论中指出的那样,此解决方案可能会破坏您的系统。
You most likely don't want to remove python3.
您很可能不想删除 python3。
Please refer to the other answers for possible solutions.
有关可能的解决方案,请参阅其他答案。
Outdated answer (not recommended)
过时的答案(不推荐)
sudo apt-get remove 'python3.*'
sudo apt-get remove 'python3.*'
回答by Hazem
Removing Python 3 was the worst thing I did since I recently moved to the world of Linux. It removed Firefox, my launcher and, as I read while trying to fix my problem, it may also remove your desktop and terminal! Finally fixed after a long daytime nightmare. Just don't remove Python 3. Keep it there!
自从我最近搬到 Linux 世界以来,删除 Python 3 是我做的最糟糕的事情。它删除了 Firefox,我的启动器,并且正如我在尝试解决问题时所读到的那样,它还可能删除了您的桌面和终端!经过漫长的白天噩梦终于解决了。只是不要删除 Python 3。保留它!
If that happens to you, here is the fix:
如果您遇到这种情况,这里是解决方法:
https://askubuntu.com/q/384033/402539
https://askubuntu.com/q/384033/402539
回答by SHISH PAL
First of all, don't try the following command as suggested by Germain above.
首先,不要按照上面 Germain 的建议尝试以下命令。
`sudo apt-get remove 'python3.*'`
In Ubuntu, many software depends upon Python3 so if you will execute this command it will remove all of them as it happened with me. I found following answer useful to recover it.
在 Ubuntu 中,许多软件都依赖于 Python3,因此如果您执行此命令,它将像我一样删除所有软件。我发现以下答案对恢复它很有用。
If you want to use different python versions for different projects then create virtual environments it will be very useful. refer to the following link to create virtual environments.
如果你想为不同的项目使用不同的 python 版本,那么创建虚拟环境将非常有用。请参考以下链接创建虚拟环境。
Creating Virtual Environment also helps in using Tensorflow and Keras in Jupyter Notebook.
创建虚拟环境还有助于在 Jupyter Notebook 中使用 Tensorflow 和 Keras。
https://linoxide.com/linux-how-to/setup-python-virtual-environment-ubuntu/
https://linoxide.com/linux-how-to/setup-python-virtual-environment-ubuntu/
回答by sammy mutahi
Its simple just try: sudo apt-get remove python3.7 or the versions that you want to remove
它很简单,只需尝试: sudo apt-get remove python3.7 或您要删除的版本
回答by Saurabh Verma
neither try any above ways nor sudo apt autoremove python3
because it will remove all gnome based applications from your system including gnome-terminal. In case if you have done that mistake and left with kernal only than trysudo apt install gnome
on kernal.
既不要尝试上述任何方法,也不要sudo apt autoremove python3
因为它会从您的系统中删除所有基于 gnome 的应用程序,包括 gnome-terminal。如果你犯了那个错误并且只留下内核而不是尝试sudo apt install gnome
内核。
try to change your default python version instead removing it. you can do this through bashrc fileor export pathcommand.
尝试更改您的默认 python 版本而不是删除它。您可以通过bashrc 文件或导出路径命令执行此操作。