Ubuntu17.04 执行add-apt-repository时报错No module named 'softwareproperties'

来源:互联网 发布:minecraft 1.8 mac 编辑:程序博客网 时间:2024/06/11 23:30
在搞Ubuntu主题时用到了add-apt-repository,执行一直报错,报错内容如下:
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 10, in <module>
    from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
ModuleNotFoundError: No module named 'softwareproperties'


定位add-apt-repository,在目录/usr/bin目录下,打开发现这是用Python编写的,因为之前安装anaconda,把/usr/bin/python改掉了,换成了python3.6了,然后进入python3.6的解释器执行语句: from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler果断报错,如下:
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'softwareproperties'


然后进入python2.7的解释器在执行上述语句,报错如下:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name shortcut_handler


原来是因为Python版本不同,Python的模块有些许的不同,正好我的系统里还装有Python3.5(这个是系统自带的),执行上述语句,结果如下:
>>> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
Traceback (most recent call last):
  File "/usr/bin/lsb_release", line 25, in <module>
    import lsb_release
ModuleNotFoundError: No module named 'lsb_release'
Traceback (most recent call last):
  File "/usr/bin/lsb_release", line 25, in <module>
    import lsb_release
ModuleNotFoundError: No module named 'lsb_release'


现在不报模块的错误了,那就直接将add-apt-repository中的第一行改为#!/usr/bin/python3.5 即可。
问题解决。
阅读全文
0 0