首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从源代码安装Python3.6.3后没有名为“lsb_release”的模块

从源代码安装Python3.6.3后没有名为“lsb_release”的模块
EN

Ask Ubuntu用户
提问于 2017-10-15 07:20:27
回答 1查看 32.9K关注 0票数 19

平台:Ubuntu17.04服务器

Ubuntu17.04服务器安装包括python2.7和python3.5。我从源代码手动安装了Python3.6.3。然而,lsb_release -a失败了:

代码语言:javascript
运行
复制
# 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'

但是,如果我修改文件lsb_release的第一行

代码语言:javascript
运行
复制
#!/usr/bin/python3 -Es

代码语言:javascript
运行
复制
#!/usr/bin/python3.5 -Es

它又起作用了。

代码语言:javascript
运行
复制
# 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

下面是模块搜索路径:

代码语言:javascript
运行
复制
# 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()

有人知道怎么修吗?

EN

回答 1

Ask Ubuntu用户

发布于 2018-02-06 12:20:47

解决方案:

代码语言:javascript
运行
复制
sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.6/site-packages/lsb_release.py

解释:

我们可以在/usr/bin/lsb_release中看到

代码语言:javascript
运行
复制
#!/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

关键步骤是import lsb_release,但问题是Python 3.6没有这个模块。

因此,您必须将python3python3.5过度到python3.6**。这就是为什么你的** lsb_release坏了。

要验证它,我们可以在python3.6中看到:

代码语言:javascript
运行
复制
➜  ~ 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'

然后在python3.5中:

代码语言:javascript
运行
复制
➜  ~ 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'

这份文件在哪里:

代码语言:javascript
运行
复制
➜  ~ 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

因此,该模块lsb_release存在于python3.5中,而不存在于python3.6中。我们最终会找到的!

现在,让我们通过添加到原始lsb_release.py文件的链接来修复它!

这对我有用!

票数 50
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/965043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档