Ningún módulo llamado 'lsb_release' después de instalar Python 3.6.3 desde la fuente


10

plataforma: servidor ubuntu 17.04

La instalación del servidor ubuntu 17.04 incluye python 2.7 y python 3.5. Instalé Python 3.6.3 manualmente desde la fuente. Sin embargo, lsb_release -afalló:

# 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'

Pero si modifico la primera línea del archivo lsb_releasede

#!/usr/bin/python3 -Es

a

#!/usr/bin/python3.5 -Es

Funciona de nuevo.

# 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

Aquí está la ruta de búsqueda del módulo:

# 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
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()

¿Alguien sabe cómo arreglarlo?


1
Creo que probablemente debería simplemente rm / usr / local / bin / python3, y usar python3.6 explícitamente si desea usar 3.6 para algo.
— dobey

¿Por qué estás instalando Python 3.6 desde la fuente?
— edwinksl

Parece que configuró una instalación de Python diferente como predeterminada en su sistema Ubuntu. Se sabe que esto causa muchos problemas debido a las diferentes rutas de instalación del módulo. ¿Cuál es el resultado de readlink -f /usr/bin/python3y /usr/bin/python3 --version?
— David Foerster

Respuestas:


23

Solución:

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

Explique:

Podemos ver en /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

El paso clave es import lsb_release, pero el problema es Python 3.6que no tiene este módulo.

Por lo tanto, debe haber anulado python3de python3.5a python3.6. Por eso tu lsb_releaseestá roto.

Para verificarlo, podemos ver en 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'

luego en 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'

donde esta este archivo:

➜  ~ 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

Entonces, este módulo lsb_releaseexiste python3.5pero no existe en python3.6. ¡Y lo encontramos eventualmente!

¡Ahora solucionémoslo agregando un enlace al lsb_release.pyarchivo original !

¡Esto funciona para mi!

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.