"ImportError: No module named _struct" configuring python-minimal

Solution 1:

Follow the solution by Soroosh. Broken python (2.7) after manually building and installing python 2.6

Enter sudo -i for root access.

Paste the command and wait about 20 minutes. Runs perfectly.

for pkg in $(dpkg --get-selections | egrep -v 'deinstall' | egrep python | awk '{print $1}'); do  apt-get -y --force-yes install --reinstall $pkg ; done

Solution 2:

OK, going through the packages, I found that python-minimal does not have struct.py, but python-minimal2.7 does.

So, try this and see if it helps you out:

sudo apt-get install --reinstall python2.7-minimal
sudo apt-get upgrade

If even that does't work, perhaps your $PYTHONPATH is messed up somehow.

nano ~/.bashrc

Add the line export PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7" then

source ~/.bashrc

And try your update yet again.

Solution 3:

Try this

sudo apt purge libpython*

I removed python2.7 and 3.7, then deleted related files from the system. After that I found I can't reinstall python2.7 Tried many methods still not working, including :

remove soft links

del virtual env dirs

autoremove

sudo dpkg --purge `dpkg --get-selections | grep deinstall | cut -f1`

Then I found some libpython files by searching python whole system.(Do not rm files from dir if you are not sure.) After removed libpython* packages(I removed them one by one.), python installed successfully.

Hope this can help some people have same problems