【问题标题】:How to completely uninstall python 2.7.13 on Ubuntu 16.04如何在 Ubuntu 16.04 上完全卸载 python 2.7.13
【发布时间】:2017-06-17 07:57:42
【问题描述】:

我根据this guide在Ubuntu 16.04上安装了Python 2.7.13,它成为了默认版本,作为2.7.12版本的替代。但是,我想完全删除 Python 2.7.13 并返回到版本 2.7.12 作为默认版本,因为 pip 命令不起作用,出现以下错误。

bash: /usr/local/bin/pip: /usr/bin/python: bad interpreter: No such file or directory

您能帮我如何从 Ubuntu 16.04 中完全删除 Python 2.7.13 吗?否则,您能否建议如何解决上述错误?

【问题讨论】:

  • 在做任何其他事情之前我建议你运行$ sudo apt install --reinstall python python-apt python2.7-minimal; ubuntu 依赖于一个有效的 python2 安装!你的问题可能更适合这里:askubuntu.com

标签: python python-2.7 ubuntu ubuntu-16.04


【解决方案1】:

我该怎么做:

# Remove python2
sudo apt purge -y python2.7-minimal

# You already have Python3 but 
# don't care about the version 
sudo ln -s /usr/bin/python3 /usr/bin/python

# Same for pip
sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip

# Confirm the new version of Python: 3
python --version

【讨论】:

  • 就我而言,sudo apt purge -y python2.7-minimal 这个 sudo apt purge python2.7-minimal 有效!!但是在按下 Enter 键后,我必须输入 Yes, do as I say! N.B.我在 Linux Mint 19.3 而不是 Ubuntu 中使用它。谢谢@Benoit Mrx
  • 所以,如果你加上 -y 就不需要说是了!
  • 是的!但很简单,它没有使用 -y !我知道为什么,但它只能通过重新输入确认字符串来授予权限是的,照我说的做!
【解决方案2】:

注意:不建议从 Ubuntu 中删除默认的 Python,这可能会导致 GDM(提供图形登录功能的图形显示管理器)失败。

要完全卸载 Python2.x.x,一切都取决于它。使用这个命令:

sudo apt purge python2.x-minimal

因为仍然有很多依赖 Python2.x.x 的包。因此,在继续执行之前,您应该仔细查看 apt 想要删除的软件包。

谢谢,希望对你有帮助。

【讨论】:

    【解决方案3】:

    这是我在清除所有 python 版本并仅重新安装 3.6 之后所拥有的。

    root@esp32:/# python
    Python 3.6.0b2 (default, Oct 11 2016, 05:27:10) 
    [GCC 6.2.0 20161005] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    root@esp32:/# python3
    Python 3.8.0 (default, Dec 15 2019, 14:19:02) 
    [GCC 6.2.0 20161005] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    

    pip 和 pip3 命令也完全是 f up:

    root@esp32:/# pip
    Traceback (most recent call last):
      File "/usr/local/bin/pip", line 7, in <module>
        from pip._internal.cli.main import main
      File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
        sys.stderr.write(f"ERROR: {exc}")
                                       ^
    SyntaxError: invalid syntax
    
    root@esp32:/# pip3
    Traceback (most recent call last):
      File "/usr/local/bin/pip3", line 7, in <module>
        from pip._internal.cli.main import main
      File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
        sys.stderr.write(f"ERROR: {exc}")
                                       ^
    SyntaxError: invalid syntax
    

    我在 Linux 上完全是菜鸟,我只是想将 Python 从 2.x 更新到 3.x,以便 Platformio 可以升级,现在我把它看起来的一切都搞砸了。

    【讨论】:

      【解决方案4】:

      尝试关注以查看所有 python 实例

      whereis python
      which python
      

      然后使用以下命令删除所有实例:

      sudo apt autoremove python
      

      重复 sudo apt autoremove python(适用于所有版本) 应该这样做,然后安装 Anaconda 并根据需要管理 Python,如果需要重新安装它。

      【讨论】:

      • 无法以这种方式卸载。无论如何它仍然在系统中...sudo apt autoremove python Reading package lists... Done Building dependency tree Reading state information... Done Package 'python' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded. 然后再次:sudo apt remove python2.7 然后:python --version 输出:Python 2.7.12
      • 此命令删除了我的 GUI 的一些依赖项并使我的 ubuntu-desktop 停止工作,这也删除了 google-chrome-stable 和其他软件包。我真的不知道我为什么要运行它,呵呵
      • 不要执行自动删除,它也会删除其他包。
      • 如果我没记错autoremove 将删除环境中不再需要的包或依赖项。
      • 好评论毁了 SO
      【解决方案5】:
      sudo apt purge python2.7-minimal
      

      【讨论】:

        【解决方案6】:

        有时您需要先更新 apt repo 列表。

        sudo apt-get update
        sudo apt purge python2.7-minimal
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-04-04
          • 1970-01-01
          • 1970-01-01
          • 2021-11-19
          • 2018-07-31
          • 2018-06-22
          • 2022-11-08
          相关资源
          最近更新 更多