I have a problem with a Debian server that I use for multiple purposes. Yesterday I tried to upgrade my packages with a simple apt-get update / upgrade as usual and found everything to be broken :

Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  owncloud owncloud-config-apache owncloud-server
The following packages will be upgraded:
1 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
Need to get 0 B/171 kB of archives.
After this operation, 47.1 kB disk space will be freed.
Do you want to continue? [Y/n]
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
(Reading database ... 83301 files and directories currently installed.)
Preparing to unpack .../python-apt_0.9.3.12_amd64.deb ...
/var/lib/dpkg/info/python-apt.prerm: /usr/bin/pyclean: /usr/bin/python: bad interpreter: No such file or directory
dpkg: warning: subprocess old pre-removal script returned error exit status 126
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: /usr/bin/pyclean: /usr/bin/python: bad interpreter: No such file or directory
dpkg: error processing archive /var/cache/apt/archives/python-apt_0.9.3.12_amd64.deb (--unpack):
 subprocess new pre-removal script returned error exit status 126
/var/lib/dpkg/info/python-apt.postinst: /usr/bin/pycompile: /usr/bin/python: bad interpreter: No such file or directory
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 126
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

Since then I've tried applying a bunch of solutions including the recommendations of a dpkg --audit as well as suggested solutions here and on other community help websites for similar issues, to no avail.

It also appears that even after fixing the locale issue that perl mentions, it reappears if I quit my ssh session and open a new one.

Any ideas how I can fix this ? (besides reinstalling from scratch which I'd rather avoid if possible.)


EDIT (updated): As per requested by @Gilles, here is the result of ls -l /usr/bin/python; ls -lL /usr/bin/python; dpkg -S /usr/bin/python

ls: cannot access /usr/bin/python: No such file or directory
ls: cannot access /usr/bin/python: No such file or directory
python-minimal: /usr/bin/python

I have no recollection of ever changing python settings manually.

  • Did you run dpkg-reconfigure locales? – Jodka Lemon Oct 2 '15 at 13:44
  • Yes, and the problem persists. – kRYOoX Oct 2 '15 at 13:49
  • There's something seriously wrong about /usr/bin/python. Did you change it manually? Please edit your question to add the output of ls -l /usr/bin/python; ls -lL /usr/bin/python; dpkg -L /usr/bin/python – Gilles Oct 2 '15 at 22:26
  • @Gilles, I've added my answer to the question. – kRYOoX Oct 3 '15 at 10:40
  • Sorry, I meant dpkg -S /usr/bin/python for the third command. The absence of /usr/bin/python causes your immediate problem, but I wonder how you ended up without it. The output of apt-cache policy python-minimal might help too. The Perl locale issue is unrelated, by the way; the problem there is that UTF-8 is not a valid value for LC_CTYPE, you should set LC_CTYPE=en_US.UTF-8 and not set LANG, or set LANG=en_US.UTF-8 and leave LC_CTYPE unset. – Gilles Oct 3 '15 at 11:19
/var/lib/dpkg/info/python-apt.postinst: /usr/bin/pycompile: /usr/bin/python: bad interpreter: No such file or directory

That error indicates that /usr/bin/python is broken in some ways. Most Python scripts won't be able to run.

When the python-apt package is installed, it runs a Python script. This fails, so the installation of the package can't complete. Although APT can proceed with other packages even if one fails, this might require running apt-get -f install a few times and might prevent upgrades that shuffle dependencies around. And anyway a broken Python is going to break a lot of software.

$ ls -l /usr/bin/python
ls: cannot access /usr/bin/python: No such file or directory
$ dpkg -S /usr/bin/python
python-minimal: /usr/bin/python

/usr/bin/python doesn't exist at all. But the packaging system thinks that it's installed.

Reinstall the package that contains /usr/bin/python:

sudo apt-get --reinstall install python-minimal
sudo apt-get -f install

If the absence of /usr/bin/python is the only problem, that should repair your system. But whatever caused /usr/bin/python to disappear might have caused other problems.

Try to find out what could have caused /usr/bin/python to disappear. This doesn't normally happen if you use dpkg and apt to manage packages. Make sure that if you install any software without using the package manager, it goes under /opt or /usr/local, never directly under /usr.

  • Thank you very much. Your solution indeed worked. As of now, I really have no idea how python could have become so damaged, seeing as I didn't do anything python related for months now. Nevertheless, I'll dig and see if I can find clues about what happened. =O – kRYOoX Oct 3 '15 at 12:06

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.