在Ubuntu 16.04.6 LTS上安装python3.7和pip3后出现Command '('lsb_release', '-a')' 出错问题的解决方法

在Ubuntu 16.04.6 LTS上安装python3.7和pip3后出现Command '('lsb_release', '-a')' returned non-zero exit status 1问题解决方法

我在Ubuntu 16.04.6 LTS中将python3的版本由3.5升级到3.7.3,在安装任何模块时,比如执行下面的命令

sudo pip3 install you-get

就会出现下面的错误

Traceback (most recent call last):
  File "/usr/bin/pip3", line 10, in
    sys.exit(main())
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_internal/__init__.py", line 78, in main
    return command.main(cmd_args)
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 228, in main
    timeout=min(5, options.timeout)
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 93, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_internal/download.py", line 344, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_internal/download.py", line 108, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/distro.py", line 120, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/distro.py", line 675, in linux_distribution
    self.version(),
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/distro.py", line 735, in version
    self.lsb_release_attr('release'),
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/distro.py", line 892, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/distro.py", line 550, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/python3/lib/python3.7/site-packages/pip/_vendor/distro.py", line 998, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/local/python3/lib/python3.7/subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "/usr/local/python3/lib/python3.7/subprocess.py", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.

在Ubuntu 16.04.6 LTS上安装python3.7和pip3后出现Command '('lsb_release', '-a')' 出错问题的解决方法_第1张图片

原因是找不到lsb_release模块

解决方法:
找到lsb_release模块所在的目录,将其复制到设置python3.7的系统模块加载位置,也就是报错处subprocess.py所在的目录
/usr/local/python3/lib/python3.7/

依次执行下面的命令:
sudo find / -name 'lsb_release.py'
结果如下:
/usr/lib/python2.7/dist-packages/lsb_release.py
/usr/lib/python3/dist-packages/lsb_release.py
/usr/share/pyshared/lsb_release.py


sudo cp  /usr/share/pyshared/lsb_release.py /usr/local/python3/lib/python3.7/

同时还需要将CommandNotFound所在的目录复制到上面相同的目录下面

sudo cp -fr /usr/lib/python3/dist-packages/CommandNotFound   /usr/local/python3/lib/python3.7/

将__pycache__子目录中的文件名中带有35名字的文件更改为37,见下面截图

在Ubuntu 16.04.6 LTS上安装python3.7和pip3后出现Command '('lsb_release', '-a')' 出错问题的解决方法_第2张图片

然后再次执行上面的命令就OK了。

需要说明的是,网上参考文献[2]中说,执行下面的命令也可以解决这个问题:

sudo rm /usr/bin/lsb_release

我个人不赞成这么做,因为这破坏了系统的完整性,将系统中的这个命令删去了。

注意:系统重启后会造成gnome-terminal无法启动的坑

参见下一篇博文修正:

https://blog.csdn.net/tao_627/article/details/91042809

参考文献
[1].https://www.jianshu.com/p/3a2877edebe8
[2].https://www.cnblogs.com/longbigbeard/p/10028746.html
 

你可能感兴趣的:(Python)