在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 ×××
就会出现下面的错误
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.
原因是找不到 lsb_release 模块
解决方法:
找到lsb_release模块所在的目录,将其复制到设置python3.7的系统模块加载位置,也就是报错处subprocess.py所在的目录
/usr/local/python3/lib/python3.7/
依次执行下面的命令来查看lsb_release.py
文件所在的所有位置:
sudo locate 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
如果是在root本机环境
下,则运行如下命令复制lsb_release.py
文件到python3.7的位置:
sudo cp /usr/share/pyshared/lsb_release.py /usr/local/python3/lib/python3.7/
如果是在anaconda3版本管理
的环境下,则运行如下命令复制lsb_release.py文件到anaconda3的python3.7的位置:
sudo cp /usr/share/pyshared/lsb_release.py /home/UserName/lib/python3.7/
同时,如果还有关于CommandNotFound问题的话,还需要将CommandNotFound所在的目录复制到上面相同的目录下面
sudo cp -fr /usr/lib/python3/dist-packages/CommandNotFound /usr/local/python3/lib/python3.7/
或者是(在Anaconda环境时):
sudo cp -fr /usr/lib/python3/dist-packages/CommandNotFound /home/UserName/lib/python3.7/
将__pycache__子目录中的文件名中带有35名字的文件更改为37,见下面截图
然后再次执行上面的sudo pip3 install xxx
命令安装其他库就OK了。
需要说明的是,执行下面的命令也可以解决这个问题,但这是一个大坑,一定要注意!!!:
sudo rm /usr/bin/lsb_release
非常不赞成这么做,因为这破坏了系统的完整性,将系统中的这个命令删去了。
注意:系统重启后会造成gnome-terminal无法启动的坑
借鉴:https://blog.csdn.net/tao_627/article/details/90901563