8

platform: ubuntu 17.04 server

The ubuntu 17.04 server installation includes python 2.7 and python 3.5. I installed the Python 3.6.3 manually from source. However, the lsb_release -a failed:

root@birds:~# lsb_release -a
Traceback (most recent call last):
  File "/usr/bin/lsb_release", line 25, in <module>
    import lsb_release
ModuleNotFoundError: No module named 'lsb_release'

But if I modify the first line of the file lsb_release from
#!/usr/bin/python3 -Es to #!/usr/bin/python3.5 -Es it works again.

root@birds:~# lsb_release -a
LSB Version:    core-9.20160110ubuntu5-amd64:core-9.20160110ubuntu5-noarch:security-9.20160110ubuntu5-amd64:security-9.20160110ubuntu5-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 17.04
Release:    17.04
Codename:   zesty

Here are the module search path:

python3.5

root@birds:~# python3.5
Python 3.5.3 (default, Sep 14 2017, 22:58:41) 
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys

>>> sys.path
['', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']

>>> import lsb_release

>>> exit()

python3

root@birds:~# python3
Python 3.6.3 (default, Oct 14 2017, 20:35:42) 
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys

>>> sys.path
['', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/root/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages']

>>> import lsb_release
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lsb_release'

>>> exit()

does anyone know how to fix it? Thanks.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Richard Xu
  • 213
  • 1
  • 3
  • 7
  • Why didnt you install Python 3.6 from a PPA? – Nils Werner Oct 15 '17 at 09:06
  • Looks like you used `make install` instead of `make altinstall`? (see https://docs.python.org/3.6/using/unix.html#building-python). You *might* be able to recover by pointing the `python3` symlink at your 3.5 binary, but you might need to reinstall the entire OS. – snakecharmerb Oct 15 '17 at 09:07
  • related: https://askubuntu.com/questions/965043/no-module-named-lsb-release-after-install-python-3-6-3-from-source – Ciro Santilli OurBigBook.com May 22 '19 at 15:45

4 Answers4

18

Solution:

sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.6/site-packages/lsb_release.py

Explain:

We can see in /usr/bin/lsb_release

#!/usr/bin/python3 -Es

# lsb_release command for Debian
# (C) 2005-10 Chris Lawrence <lawrencc@debian.org>
#    This package is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; version 2 dated June, 1991.
#    This package is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this package; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#    02110-1301 USA
from optparse import OptionParser
import sys
import os
import re

import lsb_release

The key step is import lsb_release, but the problem is Python 3.6 doesn't have this module.

So, you must have overrided python3 from python3.5 to python3.6. That's why your lsb_release is broken.

To verify it, we can see in python3.6:

➜  ~ python3.6 
Python 3.6.4 (default, Feb  6 2018, 16:57:12) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsb_release
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lsb_release'

then in python3.5:

➜  ~ python3.5
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsb_release
>>> lsb_release.__file__
'/usr/lib/python3/dist-packages/lsb_release.py'

where is this file:

➜  ~ ll /usr/lib/python3/dist-packages/lsb_release.py
lrwxrwxrwx 1 root root 38 Jul   7  2016 /usr/lib/python3/dist-packages/lsb_release.py -> ../../../share/pyshared/lsb_release.py

So, this module lsb_release exist in python3.5 but not exist in python3.6. And We find it eventually!

Now let's fix it through add a link to the original lsb_release.py file!

It works for me!

Max Xu
  • 2,403
  • 1
  • 15
  • 13
  • On my machine (mint) the lsb_release runs python with the -Es flags so site-packages are not on the path. Adding the symbolic link to /usr/local/lib/python3.6/dist-packages/lsb_release.py works instead – demented hedgehog May 17 '18 at 23:06
  • it works for me at Debian GNU/Linux 11 (bullseye) aarch64, sys.path and ln -s... gave me the path to the solution – jrg Aug 18 '23 at 17:03
4

This happens when dist-packages is wiped out or not accessible to the python installation.

I got into this when I removed a dist-packages/ in /usr/lib/python3 - because there were some user-installed packages conflicting with my local packages.

To fix, you can try:

sudo apt reinstall lsb-release

This fixed it for me. It also avoids the issue with the sibling answer of purging lsb-release. No need.

tony
  • 870
  • 7
  • 16
1

I had this same problem with python 3.6 and python 3.7 on Raspberry Pi, but I thing it shall work anywhere.

The only thing that works like a charm was to move the lsb_release to a backup file.

 sudo mv /usr/bin/lsb_release /usr/bin/lsb_release_back

The complete doc can be found here: [readthedocs.io].[1]https://neoctobers.readthedocs.io/en/latest/rpi/install_python3.html

DPalharini
  • 413
  • 6
  • 16
-2

You just purge existing lsb-release and reinstall it again. It will solve your problem.

$ sudo apt purge lsb-release
$ sudo apt install lsb-release  
Rakib
  • 1,966
  • 1
  • 11
  • 15