![如何在 Ubuntu 14.04 中卸载 Python 2.7 并重新安装 3.5?](https://linux22.com/image/995475/%E5%A6%82%E4%BD%95%E5%9C%A8%20Ubuntu%2014.04%20%E4%B8%AD%E5%8D%B8%E8%BD%BD%20Python%202.7%20%E5%B9%B6%E9%87%8D%E6%96%B0%E5%AE%89%E8%A3%85%203.5%EF%BC%9F.png)
我想问一个彻底删除的方法,这样python 3就不会受到以前版本的干扰。我不确定python2.7是如何安装的,因为这不是我做的。而且我是Linux的新手,所以我真的不知道我该怎么做...
这是我检查 Python 版本时的信息。谢谢!!:)
administrator@TUBVLMF-AWR163:~$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/bin/anaconda/lib/python2.7/site.pyc matches /usr/bin/anaconda/lib/python2.7/site.py
import site # precompiled from /usr/bin/anaconda/lib/python2.7/site.pyc
# /usr/bin/anaconda/lib/python2.7/os.pyc matches /usr/bin/anaconda/lib/python2.7/os.py
import os # precompiled from /usr/bin/anaconda/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/bin/anaconda/lib/python2.7/posixpath.pyc matches /usr/bin/anaconda/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/bin/anaconda/lib/python2.7/posixpath.pyc
# /usr/bin/anaconda/lib/python2.7/stat.pyc matches /usr/bin/anaconda/lib/python2.7/stat.py
import stat # precompiled from /usr/bin/anaconda/lib/python2.7/stat.pyc
# /usr/bin/anaconda/lib/python2.7/genericpath.pyc matches /usr/bin/anaconda/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/bin/anaconda/lib/python2.7/genericpath.pyc
# /usr/bin/anaconda/lib/python2.7/warnings.pyc matches /usr/bin/anaconda/lib/python2.7/warnings.py
import warnings # precompiled from /usr/bin/anaconda/lib/python2.7/warnings.pyc
# /usr/bin/anaconda/lib/python2.7/linecache.pyc matches /usr/bin/anaconda/lib/python2.7/linecache.py
import linecache # precompiled from /usr/bin/anaconda/lib/python2.7/linecache.pyc
# /usr/bin/anaconda/lib/python2.7/types.pyc matches /usr/bin/anaconda/lib/python2.7/types.py
import types # precompiled from /usr/bin/anaconda/lib/python2.7/types.pyc
# /usr/bin/anaconda/lib/python2.7/UserDict.pyc matches /usr/bin/anaconda/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/bin/anaconda/lib/python2.7/UserDict.pyc
# /usr/bin/anaconda/lib/python2.7/_abcoll.pyc matches /usr/bin/anaconda/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/bin/anaconda/lib/python2.7/_abcoll.pyc
# /usr/bin/anaconda/lib/python2.7/abc.pyc matches /usr/bin/anaconda/lib/python2.7/abc.py
import abc # precompiled from /usr/bin/anaconda/lib/python2.7/abc.pyc
# /usr/bin/anaconda/lib/python2.7/_weakrefset.pyc matches /usr/bin/anaconda/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/bin/anaconda/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/bin/anaconda/lib/python2.7/copy_reg.pyc matches /usr/bin/anaconda/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/bin/anaconda/lib/python2.7/copy_reg.pyc
# /usr/bin/anaconda/lib/python2.7/traceback.pyc matches /usr/bin/anaconda/lib/python2.7/traceback.py
import traceback # precompiled from /usr/bin/anaconda/lib/python2.7/traceback.pyc
# /usr/bin/anaconda/lib/python2.7/sysconfig.pyc matches /usr/bin/anaconda/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/bin/anaconda/lib/python2.7/sysconfig.pyc
# /usr/bin/anaconda/lib/python2.7/re.pyc matches /usr/bin/anaconda/lib/python2.7/re.py
import re # precompiled from /usr/bin/anaconda/lib/python2.7/re.pyc
# /usr/bin/anaconda/lib/python2.7/sre_compile.pyc matches /usr/bin/anaconda/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/bin/anaconda/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/bin/anaconda/lib/python2.7/sre_parse.pyc matches /usr/bin/anaconda/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/bin/anaconda/lib/python2.7/sre_parse.pyc
# /usr/bin/anaconda/lib/python2.7/sre_constants.pyc matches /usr/bin/anaconda/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/bin/anaconda/lib/python2.7/sre_constants.pyc
# /usr/bin/anaconda/lib/python2.7/_sysconfigdata.pyc matches /usr/bin/anaconda/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/bin/anaconda/lib/python2.7/_sysconfigdata.pyc
# zipimport: found 13 names in /usr/bin/anaconda/lib/python2.7/site-packages/runipy-0.1.0-py2.7.egg
# zipimport: found 135 names in /usr/bin/anaconda/lib/python2.7/site-packages/setuptools-3.6-py2.7.egg
import encodings # directory /usr/bin/anaconda/lib/python2.7/encodings
# /usr/bin/anaconda/lib/python2.7/encodings/__init__.pyc matches /usr/bin/anaconda/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/bin/anaconda/lib/python2.7/encodings/__init__.pyc
# /usr/bin/anaconda/lib/python2.7/codecs.pyc matches /usr/bin/anaconda/lib/python2.7/codecs.py
import codecs # precompiled from /usr/bin/anaconda/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/bin/anaconda/lib/python2.7/encodings/aliases.pyc matches /usr/bin/anaconda/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/bin/anaconda/lib/python2.7/encodings/aliases.pyc
# /usr/bin/anaconda/lib/python2.7/encodings/utf_8.pyc matches /usr/bin/anaconda/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/bin/anaconda/lib/python2.7/encodings/utf_8.pyc
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 2 2014, 12:34:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
dlopen("/usr/bin/anaconda/lib/python2.7/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/bin/anaconda/lib/python2.7/lib-dynload/readline.so
答案1
默认情况下,在最新的 Ubuntu 版本中已经包含了 python 和 python3,如果你完全删除 python 2.7,它可能会破坏你的系统终端类型
python3
打开 Python 3 解释器,运行脚本时输入
python3 Scriptname
如果尚未包含,请在终端中输入
sudo apt-get update && sudo apt-get install python3
玩得开心 :)
答案2
我不确定如何安装 python2.7,因为这不是我做的。而且我对 Linux 完全陌生,所以我真的不知道我该怎么做...
首先,检查您是否已手动安装 python2.7,请执行以下操作
apt show python2.7
在所有这些信息中,有一行APT-Manual-Installed: no
。如果这是 NO,您可能不应该卸载它!对于所有软件包,此规则通常都是正确的。
因此,正如所说,删除 python2.7 是不明智的。我建议简单地在 bash 的配置文件中添加一个别名,这样当您python
在终端中写入时,它就像写入一样python3
。这很有用,但可能会造成误解。
怎么做
添加
alias python=python3
在文件底部~/.bashrc
(或简单来说echo "alias python=python3" >> ~/.bashrc
)
然后做:
source ~/.bashrc
从终端使用更改来更新 bash。