平台:ubuntu 17.04服务器
ubuntu 17.04服务器安装包括python 2.7和python 3.5。
我从源手动安装了Python 3.6.3。但是,lsb_release -a
失败了:
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'
但是,如果我修改文件lsb_release的第一行
#!/usr/bin/python3 -Es
至
#!/usr/bin/python3.5 -Es
它又有效了。
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
以下是模块搜索路径:
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()
有谁知道如何修复它?感谢。
答案 0 :(得分:8)
<强>解决方案:强>
sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.6/site-packages/lsb_release.py
<强>说明:强>
我们可以在/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
关键步骤是import lsb_release
,但问题是Python 3.6
没有此模块。
所以,您必须覆盖从python3
到python3.5
的{{1}}。这就是你python3.6
被打破的原因。
要验证它,我们可以在lsb_release
中看到:
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'
:
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'
因此,此模块➜ ~ 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
文件的链接来修复它!
对我有用!
答案 1 :(得分:0)
这种情况是在dist-packages
消失或无法被python安装访问时发生的。
当我在dist-packages/
中删除/usr/lib/python3
时遇到了这个问题-因为有些用户安装的软件包与我的本地软件包冲突。
要解决此问题,您可以尝试:
sudo apt reinstall lsb-release
这为我解决了。这也避免了清除lsb-release
的兄弟姐妹问题。不用。
答案 2 :(得分:0)
我在 Raspberry Pi 上使用 python 3.6 和 python 3.7 遇到了同样的问题,但我认为它可以在任何地方工作。
唯一有效的方法是将 lsb_release 移动到备份文件中。
sudo mv /usr/bin/lsb_release /usr/bin/lsb_release_back
可以在此处找到完整的文档:[readthedocs.io].[1]https://neoctobers.readthedocs.io/en/latest/rpi/install_python3.html
答案 3 :(得分:-1)
您只需清除现有的lsb发行版,然后重新安装。它将解决您的问题。
$ sudo apt purge lsb-release
$ sudo apt install lsb-release