apt install broken - ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser'
Hi all.
First post here. Yes, I have read the concerns around kali as a newbie , but since part of my using Linux was exactly for learning pentesting I guess the best place to start was with Kali 🙈. Anyway , forgive me that I am not an expert , but I guess this problem is not necessarily specific to Kali and just hope to get help since my apt is now broken. I have posted in stack exchange as well as Kali , tried googling and various ideas and still none of it seem to work. So here’s my problem and some detail. I did a sudo apt update && sudo apt full-upgrade -y and received the following error: >>>>>>>>>>>>>>>>>>>>>>>>>>>> File "/usr/bin/pycompile", line 35, in <module> from debpython.version import SUPPORTED, debsorted, vrepr, \ File "/usr/share/python/debpython/version.py", line 24, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser' >>>>>>>>>>>>>>>>>>>>>>>>>>>>> After reading, I think this is related to either a manual fiddling somewhere in /usr/bin (Now I have read never to do that, but I can't recall if ever I did in the past...), or something related to the default python version the distro requires. This is what I can see in terms of the python on the system: /usr/bin/python is a link to python2 and python2 is a link to python2.7. Not sure if this is pointing to the correct version or even related to the error above? Python -V shows : 2.7.18 After some advise received , I tried : >>>>>>>>>>>>>>>>>>>>>>>>>>>> sudo apt -f --reinstall install python-configparser & This is what I got : Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded. 2 not fully installed or removed. Need to get 62.6 kB of archives. After this operation, 0 B of additional disk space will be used. Get:1 http://kali.download/kali kali-rolling/main amd64 python-configparser all 3.5.0b2-3 [62.6 kB] Fetched 62.6 kB in 1s (57.7 kB/s) (Reading database ... 402234 files and directories currently installed.) Preparing to unpack .../python-configparser_3.5.0b2-3_all.deb ... Unpacking python-configparser (3.5.0b2-3) over (3.5.0b2-3) ... Setting up mercurial-common (5.4.1-1) ... Traceback (most recent call last): File "/usr/bin/pycompile", line 35, in <module> from debpython.version import SUPPORTED, debsorted, vrepr, \ File "/usr/share/python/debpython/version.py", line 24, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser' dpkg: error processing package mercurial-common (--configure): installed mercurial-common package post-installation script subprocess returned error exit status 1 Setting up python-configparser (3.5.0b2-3) ... Traceback (most recent call last): File "/usr/bin/pycompile", line 35, in <module> from debpython.version import SUPPORTED, debsorted, vrepr, \ File "/usr/share/python/debpython/version.py", line 24, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser' dpkg: error processing package python-configparser (--configure): installed python-configparser package post-installation script subprocess returned error exit status 1 dpkg: dependency problems prevent configuration of mercurial: mercurial depends on mercurial-common (= 5.4.1-1); however: Package mercurial-common is not configured yet. dpkg: error processing package mercurial (--configure): dependency problems - leaving unconfigured Errors were encountered while processing: mercurial-common python-configparser mercurial >>>>>>>>>>>>>>>>>>>>>>>>>>>>> I still get the error. Also noticed that ConfigParser is present in /usr/lib/python2.7 : >>>>>>>>>>>>>>>>>>>>>>>>>>>>> ⚡ ls /usr/lib/python2.7 | grep Con & this is what I get : ConfigParser.py ConfigParser.pyc >>>>>>>>>>>>>>>>>>>>>>>>>>>>> I now get this message even when trying to install posix man pages package as example. So everything on APT is then broken ? Any ideas on how to troubleshoot or fix this please ? |
Well, /usr/bin/pycompile and /usr/share/python/debpython/version.py are part of the package python2-minimal. Dependency chain probably looks like this:
mercurial -> python2 -> python2-minimal What packages will be removed if you purge python2-minimal? Simulate it with Code:
apt -s purge python2-minimal |
Quote:
The output of the simulation is too huge to post here(75K CHARACTERS), not sure what exactly I should be looking at(sorry no clue wrt python and it's setup, but if you can please give me an idea so I can post only the relevant ? or let me know how else ? ). here is also out from the reverse dependency lists. not sure if you can note anything from this. Code:
✘ ⚡ root@kali /home/juju apt-cache rdepends mercurial Code:
⚡ root@kali /home/juju apt-cache rdepends python2-minimal Code:
⚡ root@kali /home/juju apt-cache rdepends python2 Code:
⚡ root@kali /home/juju apt -s purge python2-minimal |
That's interesting. I didn't realize so many things still depend on python2 in kali-rolling. To compare, this is what I get on Ubuntu 20.04 with quite a few packages installed (5140):
Code:
$ apt -s purge python2-minimal Quote:
Code:
$ apt-cache rdepends python2-minimal OTOH, in Ubuntu 18.04 there's no package python2-minimal, only python-minimal (which was renamed python2-minimal in later releases) and python3-minimal. |
Quote:
Why does it seem my stuff is duplicated(dependancy packages showing twice in redepends output) see a few examples below. I see even python3-minimal show this duplicates Code:
⚡ root@kali /home/juju apt-cache rdepends python3-minimal Code:
⚡ root@kali /home/juju apt-cache rdepends python2-minimal Code:
⚡ root@kali /home/juju apt-cache rdepends python-minimal Code:
⚡ root@kali /home/juju apt-cache rdepends python Here is configparser Code:
⚡ root@kali /home/juju apt-cache rdepends python-configparser Code:
⚡ root@kali /home/juju apt-cache rdepends python2 |
I don't use Kali, so it's hard for me to say how it should be done there. I'd try to reinstall python2-minimal because the error message seems to originate there.
Code:
apt -f reinstall python2-minimal |
Quote:
Presumably something python related, or adding some extremely ill-advised repo or deb. Failing that, nuke it and re-install, or better yet, run it live as intended, and don't repeat the mistake. Apt relies on a working python backend, and all this fussing about is just wasting everyone's time (including yours) and teaching you nothing. |
Quote:
Additionally you did not tell us which version of that OS was installed, if it was a VM, if it was a live CD (and any other details). Probably reinstall is the best you can do now as it was already suggested. |
Kali is not meant to be updated like a normal desktop OS. It has lots of customization added to make the various pen-testing applications work. This is why they say to use it as a live USB/CD.
Your best option to wipe and start over and not treat it like a desktop. |
Quote:
Apologies missed that version as I cut and pasted here So after the apt full upgrade it’s 2020.3 and it’s running on vbox. This kinda prob can pop up in any Linux distro, not so ? So if you can Just imagine for sec that it’s Ubuntu throwing you this python error , how would you go about troubleshooting and fixing ? I would really like to take it as a learning opportunity rather than just re-installing cause that way I learn nothing. |
Quote:
The only entry in my kali debs is the std kali.org rolling Oops 🙊, mods may close did not want to waste anyone’s time. |
Quote:
|
Quote:
Quote:
Quote:
|
Quote:
|
solved
Mods, apologies upfront as I do not want to waste more of peoples time here, but just in-case someone search I want to document what I did to solve this :
After various other forums etc etc.... and doing a lot of experimenting :-). nothing worked. So, as per above tried the #apt-cache rdepends commands again on all python,python2,python3 and the python#-minimal packages and noticed that python2.7 was often showing duplicates in the outputs. Then tried #dpkg -V (package) on the various different python packages and python2-minimal basically gave me a weird output with some "?" on the left and mentioned pycompile(sorry I did not screenshot that at the time) but it was the only one showing any output and at that time i decided python2.7 was perhaps broken. So proceeded as follows : Linked my /usr/bin/ python to python3 #sudo ln -s /usr/bin/python3 /usr/bin/python and then, verified the version to make sure it's pointing somewhere #python --version. Then, did an autoremove : #apt autoremove and,finally i purged 2.7 minimal #sudo apt purge -y python2.7-minimal. Finallly I could use apt without any issues. and , did a : #apt clean #sudo dpkg --force-all --configure -a and so far everything seems fine. So I immediately powered off and took a vm snapshot and could start up pretty normal after all that. I have since also managed to do another #sudo apt update && sudo apt full-upgrade -y and all went smooth. |
All times are GMT -5. The time now is 12:59 AM. |