7

Randomly got this error while trying to sudo apt-get upgrade and already tried to run apt-get -f install without success, what should i do?

Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 libpython3.7-stdlib : Depends: libpython3.7-minimal (= 3.7.3-1+xenial1) but 3.7.3-2~16.04.york0 is installed
 python3.7 : Depends: libpython3.7-stdlib (= 3.7.3-2~16.04.york0) but 3.7.3-1+xenial1 is installed
E: Unmet dependencies. Try using -f.

edit:

apt policy python3.7 libpython3.7-stdlib libpython3.7-minimal output

python3.7:
  Installed: 3.7.3-2~16.04.york0
  Candidate: 3.7.3-2~16.04.york0
  Version table:
 *** 3.7.3-2~16.04.york0 500
        500 http://ppa.launchpad.net/jonathonf/python-3.7/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
     3.7.3-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 Packages
libpython3.7-stdlib:
  Installed: 3.7.3-1+xenial1
  Candidate: 3.7.3-2~16.04.york0
  Version table:
     3.7.3-2~16.04.york0 500
        500 http://ppa.launchpad.net/jonathonf/python-3.7/ubuntu xenial/main amd64 Packages
 *** 3.7.3-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
libpython3.7-minimal:
  Installed: 3.7.3-2~16.04.york0
  Candidate: 3.7.3-2~16.04.york0
  Version table:
 *** 3.7.3-2~16.04.york0 500
        500 http://ppa.launchpad.net/jonathonf/python-3.7/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
     3.7.3-1+xenial1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 Packages

sudo apt install libpython3.7-stdlib output

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python3.7-distutils python3.7-lib2to3
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  libpython3.7-stdlib
1 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1748 kB of archives.
After this operation, 91,1 kB disk space will be freed.
(Reading database ... 303775 files and directories currently installed.)
Preparing to unpack .../libpython3.7-stdlib_3.7.3-2~16.04.york0_amd64.deb ...
Unpacking libpython3.7-stdlib:amd64 (3.7.3-2~16.04.york0) over (3.7.3-1+xenial1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.7-stdlib_3.7.3-2~16.04.york0_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.7/distutils/__init__.py', which is also in package python3.7-distutils 3.7.3-1+xenial1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.7-stdlib_3.7.3-2~16.04.york0_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
8
  • Can you edit your question and add the output of apt policy python3.7 libpython3.7-stdlib libpython3.7-minimal please?
    – Byte Commander
    May 9, 2019 at 23:26
  • Have you been getting packages from here and if so how were at least 1 installed?? cloudsmith.io/~agriconnect/repos/debian/packages/…
    – doug
    May 9, 2019 at 23:34
  • @doug i haven't
    – Eduardo
    May 9, 2019 at 23:53
  • Can you edit your question and add the output of sudo apt install libpython3.7-stdlib ?
    – Olimjon
    May 10, 2019 at 0:01
  • Ok, so 2 python3 ppa's with conflicting package contents. See this answer as how to force an overwrite with apt-get. askubuntu.com/questions/56761/…
    – doug
    May 10, 2019 at 0:41

3 Answers 3

10

Diagnosing:

See what sudo apt upgrade says:

myself@box:~$ sudo apt upgrade
[sudo] password for myself: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libpython3.7-stdlib : Depends: libpython3.7-minimal (= 3.7.13-1+bionic1) but 3.7.13-1+bionic3 is installed
 python3.7 : Depends: libpython3.7-stdlib (= 3.7.13-1+bionic3) but 3.7.13-1+bionic1 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

Conclusion: something is wrong with some Python 3.7 packages.


Overview - one Python version:

List all the Python 3.7 packages. Good to compare this listing before and after you implement the solution.

# Command:
sudo dpkg -l | grep 'python3\.7' | awk '{print $2}'

# Output:
libpython3.7-minimal:amd64
libpython3.7-stdlib:amd64
python3.7
python3.7-distutils
python3.7-lib2to3
python3.7-minimal
python3.7-venv

Solution - one Python version:

No need to remove/purge the deadsnakes ppa. This worked for me on Ubuntu 18.04

  1. Issue this command to delete all Python 3.7 packages:

     myself@box:~$ sudo apt --fix-missing purge $(dpkg -l | grep 'python3\.7' | awk '{print $2}')
    
  2. Answer Y to execute the removal of the listed packages.

  3. Install the same packages again:

    • Alternative A) SLOWER AND SMARTER VERSION: Install only the packages you know you want to install, they will be set by apt as manually installed:

       myself@box:~$ sudo apt install python3.7 python3.7-venv
      

      and see if the other packages are installed automatically as dependencies. If not, install the other missing packages manually, too.

    • Alternative B) FASTER AND DUMBER VERSION: Copy the package names from the list created by apt --fix-missing purge, remove the stars and install them (again):

      myself@box:~$ sudo apt install libpython3.7-minimal libpython3.7-stdlib python3.7 python3.7-minimal python3.7-venv
      
  4. Not a must: check with the Overview-command from above that you have the same packages installed now, as before implementing the solution.


Overview - several Python versions:

List all the packages for all the Python-versions needed, for me 3.7, 3.10 and 3.11. Good to compare this listing before and after you implement the solution.

sudo dpkg -l | grep 'python3\.7\|python3\.10\|python3\.11' | awk '{print $2}'

Solution - several Python versions at once:

  1. Do as above, but use this command instead. Fill in the Python versions that are failing. For me they were 3.7, 3.10 and 3.11

     sudo apt --fix-missing purge $(dpkg -l | grep 'python3\.7\|python3\.10\|python3\.11' | awk '{print $2}')
    
  2. Answer Y

  3. Install the Pythons again. I did not have/need venv for 3.11, so:

     sudo apt install python3.11 python3.10 python3.10-venv python3.7 python3.7-venv
    
  4. Not a must: check with the Overview-command from above that you have the same packages installed now, as before implementing the solution.


Source and explanation of each part of the command (#1) are found here https://askubuntu.com/a/1402567

2
  • 1
    This should be voted as an answer. Most people may only need the "Solution - one Python version" section.
    – fchen
    Jun 17 at 14:36
  • You are probably right, @fchen, about that most people need the one Python version solution. However, I myself needed also the several versions method, the second time this happened for me. I did not find a question concerning several Python versions, so I added it here. Jun 21 at 9:49
2

Consider to remove the problematic PPA and reinstall normal packages with:

sudo apt-get install ppa-purge
sudo ppa-purge ppa:jonathonf/python-3.7
sudo ppa-purge ppa:deadsnakes/ppa
sudo apt-get install --reinstall libpython3.5-minimal python3-minimal python3.5-minimal
sudo apt-get install --reinstall libpython3-stdlib libpython3.5-stdlib
1
  • 1
    sudo ppa-purge ppa:deadsnakes/ppa helped for me. After that, sudo apt --fix-broken install worked. Then, I added deadsnakes ppa back and everything seemed to be working ok.
    – Fonnae
    Feb 7 at 18:39
1

OK, it seems you used another PPA with higher version of the package and then removed it from your sources.list. It is not possible to make apt to downgrade the whole package version. So you need to fallback to the PPA that you have used:

sudo add-apt-repository ppa:jonathonf/python-3.7
sudo apt-get update
sudo apt-get upgrade
3
  • 1
    "It is not possible to make apt to downgrade the whole package version." Why do you think so? Downgrading to a specific version that is either available from a repo or as .deb is very well possible.
    – Byte Commander
    May 9, 2019 at 23:28
  • @ByteCommander, for specific package is possible. But for whole python packages is not possible as far as I know.
    – Olimjon
    May 9, 2019 at 23:29
  • @Olimjon tried what you suggested but i still get the same error, this is really weird because everything was fine just yesterday and i didn't change anything
    – Eduardo
    May 9, 2019 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.