5

I recently needed an updated version of Python3 for a project, so I built it from source; and I believe I made a bit of a mess. All apt based operations now end in an error here:

(Reading database ... 320897 files and directories currently installed.)
Removing nvidia-prime (0.6.2) ...
Traceback (most recent call last):
  File "/usr/bin/lsb_release", line 28, in <module>
    import lsb_release
ImportError: No module named 'lsb_release'
dpkg: error processing package nvidia-prime (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 nvidia-prime
E: Sub-process /usr/bin/dpkg returned an error code (1)

I believe the nvidia error is just more of a symptom than a problem. This was discovered when I was trying to add a source and was met with:

sudo: add-apt-repository: command not found

I'd gladly upgrade this box to 14.10, but all upgrade based commands return the same lsb_release message. Any advice on restoring my package management abilities?

Edit: Updating with python path info

lars@whorus:~/Downloads/Python-3.4.2$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       9 Dec 18 10:36 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root       9 Apr 18  2014 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3349512 Mar 22  2014 /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 Mar 23  2014 /usr/bin/python3 -> python3.4
-rwxr-xr-x 2 root root 4061272 Apr 11  2014 /usr/bin/python3.4
-rwxr-xr-x 2 root root 4061272 Apr 11  2014 /usr/bin/python3.4m
lrwxrwxrwx 1 root root      10 Mar 23  2014 /usr/bin/python3m -> python3.4m
lars
  • 63
  • 1
  • 7
  • You built python3 from source -- at what path? `/usr/bin/python` may be a symlink to a particular version; the output of `ls -l /usr/bin/python*` may be useful. – Lars Rohrbach Dec 18 '14 at 20:46
  • Yikes, unreadable output, adding to the original question – lars Dec 18 '14 at 20:55
  • This has nothing to do with nvidia, but with the Python3 program /usr/lib/lsb_release not finding its module (which should be in `/usr/lib/python3/dist_packages`). How did you configure and install python3? You don't seem to have installed over the system Python3 executables. – Anthon Dec 19 '14 at 05:54
  • (Broken record time.) Use your distributions binary packages whenever possible, people. If necessary, backport. – Faheem Mitha Mar 13 '16 at 17:50
  • Seems to have some similarities with [Repairing python setup](https://unix.stackexchange.com/q/218911). (?) – Henke Dec 21 '22 at 15:59

2 Answers2

5

Ubuntu 14.04 has the lsb_release.py file installed for Python 2.7 as well and lsb_release seems to work under python2.7 as well. You can try this by doing:

python2.7 /usr/bin/lsb_release

If that works, make a backup of the file /usr/bin/lsb_release and change the first line to read:

#! /usr/bin/python2.7

(you can experiment with the -Es options, I would leave them out intially).

Once you can run apt-get again, reinstall python3 and it dependencies. You can determine the direct dependencies by using apt-cache depends python3 and use apt-rdepends or reverse-depends (both have to be installed) to get dependencies recursively.

Anthon
  • 78,313
  • 42
  • 165
  • 222
  • Thank you sir! This was it, the first line was pointed to `#! /usr/bin/python3`. Whorus lives again, apt is upgrading like crazy. – lars Dec 26 '14 at 22:53
1

Likely you have overwritten the default python to a customized version.

head /usr/bin/lsb_release

to see what's on the header. Forcing it to specific python versions as in /usr/bin should solve the issue.

As in my case, if it writes /usr/bin/python in /usr/bin/lsb_release, change it to

/usr/bin/python2.7

o/w, change it to

/usr/bin/python3.4
Meng Zhao
  • 111
  • 4