【问题标题】:Broken python dependencies on an Ubuntu 16.04 (AWS EC2)在 Ubuntu 16.04 (AWS EC2) 上损坏了 python 依赖项
【发布时间】:2019-08-15 12:15:42
【问题描述】:

我试图在我的 Ubuntu 16.04 上删除所有已安装的 python。就目前而言,我现在明白我不应该这样做。但是,仅仅尝试重新安装 python 是行不通的。

当我尝试时

$ sudo apt install -f --reinstall python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  python3-doc python3-tk python3-venv
The following NEW packages will be installed:
  python3
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
4 not fully installed or removed.
Need to get 0 B/8,710 B of archives.
After this operation, 68.6 kB of additional disk space will be used.
Setting up python3.5-minimal (3.5.2-2ubuntu0~16.04.5) ...
# Empty sitecustomize.py to avoid a dangling symlink
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007fc6b52dd700 (most recent call first):
Aborted
dpkg: error processing package python3.5-minimal (--configure):
 subprocess installed post-installation script returned error exit status 134
dpkg: dependency problems prevent configuration of python3-minimal:
 python3-minimal depends on python3.5-minimal (>= 3.5.1-2~); however:
  Package python3.5-minimal is not configured yet.

dpkg: error processing package python3-minimal (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 python3.5-minimal
 python3-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)

$ python3
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f87215c4700 (most recent call first):
Aborted

我尝试安装一些依赖项,但我发现丢失无济于事

$ sudo apt-get -f install python3.5-minimal
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.5-minimal is already the newest version (3.5.2-2ubuntu0~16.04.5).
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 dh-python : Depends: python3:any (>= 3.3.2-2~)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

尝试了不同的方法,但此时我不知道如何解决这个问题

$ sudo apt-get -f install dh-python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
dh-python is already the newest version (2.20151103ubuntu1.1).
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 dh-python : Depends: python3:any (>= 3.3.2-2~)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

【问题讨论】:

    标签: python linux python-3.x dependencies ubuntu-16.04


    【解决方案1】:

    也许使用 sudo dpkg -i 从 deb 包安装 python 是一个更好的主意?比如from here可以下载

    【讨论】:

    • 您好,谢谢,请问我该如何获取?我正在使用虚拟服务器
    • 您好,谢谢,请问我该如何获取?我正在使用虚拟服务器
    • 您可以使用wget 下载文件。直接链接:py2.7 (amd64)py2.7 (i386)py3.5 (amd64)py3.5 (i386)
    • 哦,顺便说一句,它适用于 Ubuntu 16.04+。你用的是什么操作系统?
    • 嗯,是的,我使用的是 16.04。不过已经下载了。我仍然遇到问题$ sudo dpkg -i python3_3.5.1-3_amd64.deb dpkg: regarding python3_3.5.1-3_amd64.deb containing python3, pre-dependency problem: python3 pre-depends on python3-minimal (= 3.5.1-3) python3-minimal is unpacked, but has never been configured. dpkg: error processing archive python3_3.5.1-3_amd64.deb (--install): pre-dependency problem - not installing python3 Errors were encountered while processing: python3_3.5.1-3_amd64.deb
    【解决方案2】:

    您应该尝试: sudo apt-get update

    然后尝试使用以下命令卸载 python

    sudo apt purge python3.x-minimal

    如果卸载成功则

    sudo apt-get install python3.6

    【讨论】:

    • 嗨,谢谢。所以当我尝试卸载时; $ sudo apt purge python3.x-minimal Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package python3.x-minimal E: Couldn't find any package by glob 'python3.x-minimal' E: Couldn't find any package by regex 'python3.x-minimal'
    • @Austin - 您需要将 python3.x-minimal 中的“.x”替换为您的实际 python 版本。例如,如果你想删除 python3.5 -> sudo apt purge python3.5-minimal.
    【解决方案3】:

    ubuntu 从 16 升级到 18 后,python3 也遇到了类似的问题。但是你可以尝试在 16 上使用我的解决方案。只需使用 apt-get 对抗 apt

    注意:我需要在我的系统中安装 python2.7。

    我遵循了这些步骤:

    1. 卸载所有python3包:

      sudo apt remove python3 &amp;&amp; sudo apt autoremove

    2. 但这对我没有帮助。所以会尝试定义系统中还存在哪些包:

      apt list --installed | grep python*

      //possible output:
      WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
      libpython-stdlib/bionic,now 2.7.15~rc1-1 amd64 [installed,automatic]
      libpython2.7-minimal/bionic-updates,bionic-security,now 2.7.17-1~18.04ubuntu1.2 amd64 [installed,automatic]
      libpython2.7-stdlib/bionic-updates,bionic-security,now 2.7.17-1~18.04ubuntu1.2 amd64 [installed,automatic]
      libpython3-stdlib/bionic-updates,now 3.6.7-1~18.04 amd64 [installed]
      libpython3.5/now 3.5.2-2ubuntu0~16.04.12 amd64 [installed,local]
      libpython3.5-minimal/now 3.5.2-2ubuntu0~16.04.12 amd64 [installed,local]
      libpython3.5-stdlib/now 3.5.2-2ubuntu0~16.04.12 amd64 [installed,local]
      libpython3.6/bionic-updates,bionic-security,now 3.6.9-1~18.04ubuntu1.3 amd64 [installed,automatic]
      libpython3.6-minimal/bionic-updates,bionic-security,now 3.6.9-1~18.04ubuntu1.3 amd64 [installed,automatic]
      libpython3.6-stdlib/bionic-updates,bionic-security,now 3.6.9-1~18.04ubuntu1.3 amd64 [installed,automatic]
      python/bionic,now 2.7.15~rc1-1 amd64 [installed]
      python-apt-common/bionic-updates,bionic-updates,bionic-security,bionic-security,now 1.6.5ubuntu0.5 all [installed]
      python-minimal/bionic,now 2.7.15~rc1-1 amd64 [installed,automatic]
      python2.7/bionic-updates,bionic-security,now 2.7.17-1~18.04ubuntu1.2 amd64 [installed,automatic]
      python2.7-minimal/bionic-updates,bionic-security,now 2.7.17-1~18.04ubuntu1.2 amd64 [installed,automatic]
      
    3. 我们可以看到,系统中有一些python3包。将删除它们。

      sudo apt remove libpython3-stdlib libpython3.5 libpython3.5-minimal libpython3.5-stdlib libpython3.6 libpython3.6-minimal libpython3.6-stdlib

    4. 现在,尝试安装 python3

      sudo apt install python3

    5. 应该没问题

    【讨论】:

      猜你喜欢
      • 2016-08-16
      • 2018-06-03
      • 2021-09-09
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      相关资源
      最近更新 更多