11

I am just trying to run my normal update/upgrade and have been getting this error:

dpkg: warning: files list file for package 'libpython3.7-minimal:amd64' missing; assuming package has no files currently installed
(Reading database ... 141307 files and directories currently installed.)
Preparing to unpack .../libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb ...
Unpacking libpython3.7-stdlib:amd64 (3.7.13-1+focal3) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.7/distutils/__init__.py', which is also in package python3.7-distutils 3.7.13-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I have tried to google and look here and the solutions I have found that are recent are not working. Attempting to run Broken Fix results in:

dpkg: error processing archive /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.7/distutils/__init__.py', which is also in package python3.7-distutils 3.7.13-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.7-stdlib_3.7.13-1+focal3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
karel
  • 114,770
  • Python 3.7 is not the standard version on 20.04 (the standard is Python 3.8). So why do you have 3.7 installed in the first place? – Artur Meinild Apr 29 '22 at 09:17
  • 1
    I have the same error, and I have Python 3.7 because certain machine learning libraries are not supported under 3.8 (that's the reason for Python 3.7 on my machine at least). – cloudcell Apr 29 '22 at 20:57
  • UPDATE: For the time being, I was able to allow system upgrades by manually removing all the packages that gave me errors ("sudo dpkg --remove --force-remove-reinstreq [package name]"). However, I would seek additional advice before doing that. I just took a risk and did this because I personally found no better solutions and needed to upgrade my system, which was being blocked by this problem. – cloudcell Apr 29 '22 at 23:00
  • Thank you the "sudo dpkg --remove --force-remove-reinstreq xxxxx" allowed me to get past this problem. I am really not sure why that version of Python was on this server. I run almost everything on this server in docker as containers. I was able to resume running updates to the server. – Jeffrey Wiggins Apr 30 '22 at 22:32
  • 2

4 Answers4

17

I fixed it by removing python3.7 and its library and reinstalling it after.

This worked for me:

sudo dpkg --remove --force-remove-reinstreq python3.7 
sudo dpkg --remove --force-remove-reinstreq libpython3.7-stdlib 
sudo apt-get clean 
sudo apt-get autoremove 
sudo apt-get install python3.7
Colin
  • 13
  • What worked for me, in the end, was including the other packages that faced dependency problems in the same sudo dpkg --remove --force-remove-reinstreq command, as well as doing sudo apt-get remove --purge *python3.7* from https://askubuntu.com/a/1417603/955443 before reinstalling python – evantkchong Oct 14 '22 at 07:59
3

None of the previous answers worked for me, so I made I work with:

sudo apt-get remove --purge *python3.7*
sudo apt-get clean
sudo apt-get install python3.7-full

This was in the context of using Python from the deadsnakes repository.

LeandroN.
  • 131
1

Remove and Reinstalling python 3.7 works for me

sudo dpkg --remove --force-remove-reinstreq python3.7 
sudo dpkg --remove --force-remove-reinstreq libpython3.7-stdlib 
sudo apt-get clean 
sudo apt-get autoremove 
sudo apt-get install python3.7
Akitha_MJ
  • 291
  • 2
  • 4
0

It may be better to use Anaconda/Miniconda for non-administrative uses. You may also compile python from the source in your home folder.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz tar -xf Python-2.7.18.tgz

cd Python-2.7.18/

./configure --enable-optimizations --enable-shared --prefix=$HOME/local make -j4 make install

To use this installation add these lines into $HOME/.bashrc and source it.

export PATH=$HOME/local/bin
export LD_LIBRARY_PATH=$HOME/local/lib
export MANPATH=$HOME/local/share/man

Since different projects often use conflicting packages you may use different conda environments or use venv with your local installation

python -m venv <project_name>_env

This activate this environment use

. <project_name>_env/bin/activate

and

deactivate

to come out.