2017-10-15 729 views
1

平臺:ubuntu 17.04服務器lsb_release在安裝Python 3.6.3後無法正常工作

ubuntu 17.04服務器安裝包括python 2.7和python 3.5。 我從源碼手動安裝了Python 3.6.3。然而,lsb_release -a失敗:

[email protected]:~# 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 再次工作。

[email protected]:~# 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

[email protected]:~# 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

[email protected]:~# 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

爲什麼沒有從PPA安裝Python 3.6? –

+0

看起來像您使用'make install'而不是'make altinstall'? (請參閱https://docs.python.org/3.6/using/unix.html#building-python)。你*可能*能夠通過指向你的Python的'python3'符號鏈接來恢復。5二進制文件,但您可能需要重新安裝整個操作系統。 – snakecharmerb

回答

0

解決方案:

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 <[email protected]> 
# 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.5python3.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。我們最終找到它!

現在讓我們通過添加一個鏈接到原來的lsb_release.py文件!

它適合我!