1

So I was in the process of upgrading a Debian 8 to 9 following those instructions. Something went wrong, python broke and now I haven't been able to fix it after hours on it. Some samples:

# apt-get install --fix-broken       
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
coinor-libcoinmp1v5 kde-style-oxygen kde-style-oxygen-qt4 libboost-date-time1.62.0 libboost-filesystem1.62.0 libboost-iostreams1.62.0
...
libkf5mailcommon5 libkf5mailimporter5 libkf5messagecomposer5 libkf5messagelist5 libkf5sendlater5 libkf5templateparser5 libkjsembed4 libkntlm4
libokularcore7 liborcus-0.11-0 libpagemaker-0.0-0 libspeechd2 libwps-0.4-4
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
accountsservice akonadi-backend-mysql akonadi-server akregator apper appstream appstream-index apt apt-utils ark baloo-kf5 bluedevil bluez
...
python-mpi4py python-scipy python3 python3-apt python3-cffi-backend python3-chardet python3-crypto python3-cryptography python3-dbus
python3-debian python3-decorator python3-dev python3-gi python3-idna python3-joblib python3-keyring python3-keyrings.alt python3-minimal
python3-nose python3-numpy python3-pkg-resources python3-py python3-pyasn1 python3-pycurl python3-pyqt4 python3-pyqt5 python3-pytest
python3-secretstorage python3-setuptools python3-simplejson python3-sip python3-six python3-software-properties python3-wheel python3-xdg
python3.5 python3.5-dev qapt-batch qdbus qdbus-qt5 qml-module-org-kde-activities qml-module-org-kde-bluezqt qml-module-org-kde-draganddrop
...
task-ssh-server tasksel tasksel-data uno-libs3 ure user-manager vlc vlc-bin vlc-data vlc-l10n vlc-nox vlc-plugin-base vlc-plugin-notify
vlc-plugin-qt vlc-plugin-samba vlc-plugin-video-output
Suggested packages:
gnome-control-center akonadi-backend-postgresql akonadi-backend-sqlite limba apt-doc powermgmt-base pulseaudio-module-bluetooth bluez-alsa
...
vlc-plugin-skins2 vlc-plugin-video-splitter vlc-plugin-visualization
The following packages will be REMOVED:
aptitude coinor-libcoinmp1 coinor-libcoinutils3 coinor-libosi1 gparted juk k3b k3b-i18n kaccessible katepart kde-baseapps kde-baseapps-bin
...
task-kde-desktop vlc-plugin-pulse
The following NEW packages will be installed:
accountsservice appstream baloo-kf5 bluedevil bluez bluez-obexd breeze breeze-cursor-theme breeze-icon-theme catdoc coinor-libcoinmp1v5
...
python3-cffi-backend python3-crypto python3-cryptography python3-idna python3-keyring python3-keyrings.alt python3-py python3-pyasn1
python3-pycurl python3-pytest python3-secretstorage python3-xdg python3.5 python3.5-dev qdbus-qt5 qml-module-org-kde-activities
...
python3-debian python3-decorator python3-dev python3-gi python3-joblib python3-minimal python3-nose python3-numpy python3-pkg-resources
python3-pyqt4 python3-pyqt5 python3-setuptools python3-simplejson python3-sip python3-six python3-software-properties python3-wheel qapt-batch
qdbus qml-module-qtquick-controls qml-module-qtquick-layouts qml-module-qtquick-window2 qml-module-qtquick2 qt4-designer qt4-dev-tools
qt4-linguist-tools qt4-qmake qtbase5-dev-tools qtchooser qtcreator qtcreator-data qtdeclarative5-dev-tools qttools5-dev-tools
software-properties-kde sqlitebrowser systemsettings task-desktop task-english task-ssh-server tasksel tasksel-data uno-libs3 ure vlc vlc-data
vlc-nox vlc-plugin-notify vlc-plugin-samba
211 upgraded, 514 newly installed, 165 to remove and 243 not upgraded.
25 not fully installed or removed.
Need to get 0 B/488 MB of archives.
After this operation, 409 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Reading changelogs... Done
Extracting templates from packages: 100%
Preconfiguring packages ...
(Reading database ... 223763 files and directories currently installed.)
Preparing to unpack .../software-properties-kde_0.96.20.2-1+deb9u1_all.deb ...
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
    main()
File "/usr/lib/python3.5/site.py", line 566, in main
    known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
    user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
    USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
    return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
    _init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
    from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
    from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
dpkg: warning: subprocess old pre-removal script returned error exit status 1
dpkg: trying script from the new package instead ...
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
    main()
File "/usr/lib/python3.5/site.py", line 566, in main
    known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
    user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
    USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
    return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
    _init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
    from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
    from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
dpkg: error processing archive /var/cache/apt/archives/software-properties-kde_0.96.20.2-1+deb9u1_all.deb (--unpack):
subprocess new pre-removal script returned error exit status 1
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
    main()
File "/usr/lib/python3.5/site.py", line 566, in main
    known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
    user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
    USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
    return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
    _init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
    from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
    from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
/var/cache/apt/archives/software-properties-kde_0.96.20.2-1+deb9u1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Also on single packages:

# apt-get install --reinstall python3-minimal
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:
apper : Depends: packagekit (>= 0.8.6) but it is not going to be installed
python3 : Depends: python3-minimal (= 3.4.2-2) but 3.5.3-1 is to be installed
software-properties-kde : Depends: python3-software-properties (= 0.96.20.2-1+deb9u1) but 0.92.25debian1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

And basically the same as above with python3 or python

# dpkg --remove --force-remove-reinstreq --force-depends python3            
dpkg: python3: dependency problems, but removing anyway as you requested:
python3-pygments depends on python3:any (>= 3.3.2-2~).
software-properties-common depends on python3 (>= 3.2.3-3~).
python3-joblib depends on python3:any (>= 3.3.2-2~).
python3-debian depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-ptyprocess depends on python3:any (>= 3.3.2-2~).
python3-traitlets depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-decorator depends on python3 (>= 3.2.3-3~).
dh-python depends on python3:any (>= 3.3.2-2~).
debian-goodies depends on python3.
python3-pykde4 depends on python3 (<< 3.5).
python3-pykde4 depends on python3 (>= 3.4~).
python3-pykde4 depends on python3 (<< 3.5).
python3-pykde4 depends on python3 (>= 3.4~).
python3-setuptools depends on python3:any (>= 3.3).
python3-setuptools depends on python3:any (<< 3.5).
python3-setuptools depends on python3:any (>= 3.3).
python3-setuptools depends on python3:any (<< 3.5).
python3-software-properties depends on python3 (>= 3.2.3-3~).
python3-sip depends on python3 (>= 3.4~).
python3-sip depends on python3 (<< 3.5).
python3-sip depends on python3 (>= 3.4~).
python3-sip depends on python3 (<< 3.5).
unattended-upgrades depends on python3.
python3-pip depends on python3:any (>= 3.4~).
python3-chardet depends on python3.
python3-chardet depends on python3:any (>= 3.3.2-2~).
python3-chardet depends on python3.
python3-chardet depends on python3:any (>= 3.3.2-2~).
python3-pexpect depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-nose depends on python3; however:
Package python3 is to be removed.
python3-nose depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-nose depends on python3; however:
Package python3 is to be removed.
python3-nose depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-ipython-genutils depends on python3:any (>= 3.3.2-2~).
python3-uno depends on python3 (>= 3.4~).
python3-uno depends on python3 (<< 3.5).
python3-uno depends on python3 (>= 3.4~).
python3-uno depends on python3 (<< 3.5).
python3-pyqt4 depends on python3 (>= 3.4~).
python3-pyqt4 depends on python3 (<< 3.5).
python3-pyqt4 depends on python3 (>= 3.4~).
python3-pyqt4 depends on python3 (<< 3.5).
python3-wcwidth depends on python3:any (>= 3.3.2-2~).
lsb-release depends on python3:any (>= 3.4~).
python3-gi depends on python3 (>= 3.4~).
python3-gi depends on python3 (<< 3.5).
python3-gi depends on python3 (>= 3.4~).
python3-gi depends on python3 (<< 3.5).
python3-pkg-resources depends on python3:any (>= 3.3).
python3-pkg-resources depends on python3:any (<< 3.5).
python3-pkg-resources depends on python3:any (>= 3.3).
python3-pkg-resources depends on python3:any (<< 3.5).
python3-wheel depends on python3:any (>= 3.3.2-2~).
python3-wheel depends on python3.
python3-wheel depends on python3:any (>= 3.3.2-2~).
python3-wheel depends on python3.
gdebi-core depends on python3:any (>= 3.3.2-2~).
software-properties-kde depends on python3 (>= 3.2.3-3~).
python3-dev depends on python3 (= 3.4.2-2).
python3-six depends on python3:any (>= 3.3.2-2~).
python3-simplejson depends on python3 (>= 3.4~).
python3-simplejson depends on python3 (<< 3.5).
python3-simplejson depends on python3 (>= 3.4~).
python3-simplejson depends on python3 (<< 3.5).
python3-pyqt5 depends on python3 (>= 3.4~).
python3-pyqt5 depends on python3 (<< 3.5).
python3-pyqt5 depends on python3 (>= 3.4~).
python3-pyqt5 depends on python3 (<< 3.5).
python3-numpy depends on python3 (>= 3.4~).
python3-numpy depends on python3 (<< 3.5).
python3-numpy depends on python3 (>= 3.4~).
python3-numpy depends on python3 (<< 3.5).
python3-ipython depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
ipython3 depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-dbus depends on python3 (<< 3.5).
python3-dbus depends on python3 (>= 3.4~).
python3-dbus depends on python3 (<< 3.5).
python3-dbus depends on python3 (>= 3.4~).
python3-apt depends on python3 (<< 3.5).
python3-apt depends on python3 (>= 3.4~).
python3-apt depends on python3 (<< 3.5).
python3-apt depends on python3 (>= 3.4~).
python3-prompt-toolkit depends on python3:any (>= 3.3.2-2~); however:
Package python3 is to be removed.
python3-simplegeneric depends on python3 (>= 3.1.3-13~).
python3-pickleshare depends on python3:any (>= 3.3.2-2~).

(Reading database ... 223763 files and directories currently installed.) Removing python3 (3.4.2-2) ... Failed to import the site module Traceback (most recent call last): File "/usr/lib/python3.5/site.py", line 580, in <module> main() File "/usr/lib/python3.5/site.py", line 566, in main known_paths = addusersitepackages(known_paths) File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages user_site = getusersitepackages() File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/usr/lib/python3.5/site.py", line 253, in getuserbase USER_BASE = get_config_var('userbase') File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var return get_config_vars().get(name) File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars _init_posix(_CONFIG_VARS) File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix from _sysconfigdata import build_time_vars File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module> from _sysconfigdata_m import * ImportError: No module named '_sysconfigdata_m' dpkg: error processing package python3 (--remove): subprocess installed pre-removal script returned error exit status 1 Failed to import the site module Traceback (most recent call last): File "/usr/lib/python3.5/site.py", line 580, in <module> main() File "/usr/lib/python3.5/site.py", line 566, in main known_paths = addusersitepackages(known_paths) File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages user_site = getusersitepackages() File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/usr/lib/python3.5/site.py", line 253, in getuserbase USER_BASE = get_config_var('userbase') File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var return get_config_vars().get(name) File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars _init_posix(_CONFIG_VARS) File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix from _sysconfigdata import build_time_vars File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module> from _sysconfigdata_m import * ImportError: No module named '_sysconfigdata_m' dpkg: error while cleaning up: subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: python3

I've tried this but an error in another missing package happens:

# ln -fs /usr/lib/python3.5/plat-x86_64-linux-gnu/_sysconfigdata_m.py /usr/lib/python3.5/

A lot of things are now broken:

# lsb_release -a
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
    main()
File "/usr/lib/python3.5/site.py", line 566, in main
    known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
    user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
    USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
    return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
    _init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
    from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
    from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'

But the upgrade is halfway through:

# cat /etc/issue
Debian GNU/Linux 9 \n \l

cat /etc/os-release

PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" VERSION_CODENAME=stretch ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

ll $(which python)

lrwxrwxrwx 1 root root 9 Jan 24 2017 /usr/bin/python -> python2.7*

ll $(which python3)

-rwxr-xr-x 1 root root 11855256 Jun 13 2019 /usr/bin/python3*

Why does the installer insist on using a broken python3 instead of python (which is 2.7) ? And how do I fix this mess ?

Edit:

# apt policy python3
E: Invalid operation policy
# apt-cache policy python3
python3:
  Installed: 3.4.2-2
  Candidate: 3.5.3-1
  Version table:
     3.5.3-1 0
        500 http://httpredir.debian.org/debian/ stretch/main amd64 Packages
 *** 3.4.2-2 0
        100 /var/lib/dpkg/status

uname -a

Linux myserver2c 3.16.0-11-amd64 #1 SMP Debian 3.16.84-1 (2020-06-09) x86_64 GNU/Linux

GAD3R
  • 66,769
dargaud
  • 565
  • What does apt policy python3 say? – Stephen Kitt Mar 30 '21 at 08:51
  • Also, for future reference, you might want to follow the instructions provided by Debian when performing upgrades, instead of some random third party’s. (I don’t think there’s anything substantially incorrect in the instructions you followed, but as a general rule, please follow the Debian release notes.) – Stephen Kitt Mar 30 '21 at 08:53
  • 1
    @A.B In the specific case of upgrading from jessie to stretch, Debian's own instructions also recommend running first upgrade and then dist-upgrade. The explanation is that running dist-upgrade directly "might remove large numbers of packages that you will want to keep." – telcoM Mar 30 '21 at 10:24
  • @telcoM right. my bad ( https://www.debian.org/releases/stretch/amd64/release-notes/ch-upgrading.en.html#minimal-upgrade ) – A.B Mar 30 '21 at 10:33
  • Have 32-bit or 64-bit OS? – nobody Mar 30 '21 at 10:41
  • I added answers to the comments at the end of the original message – dargaud Mar 30 '21 at 11:33

1 Answers1

2

The problem come from the security repository, it is not set correctly.

Replace the following line described in the webpage:

deb http://security.debian.org stretch/updates main contrib non-free

with:

deb http://security.debian.org/debian-security stretch/updates main contrib non-free

Then run:

sudo apt update
sudo apt dist-upgrade

To solve the python error switch to python2.7. See Change the Python3 default version in Ubuntu. Then create a /var/lib/dpkg/info/python3.postinst with the following content:

#!/bin/bash
/bin/true

Then run:

sudo dpkg --configure -a
sudo apt update
sudo apt full-upgrade

If still doesn't work remove python3 from /var/lib/dpkg/status after backup then run the above commands.

GAD3R
  • 66,769