ubuntu16安装最新版python3.7后pip出错subprocess.CalledProcessError

如题,错误提示如下:

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/basecommand.py", line 228, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 241, in run
    with self._build_session(options) as session:
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/basecommand.py", line 81, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 338, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python3.7/site-packages/pip/_internal/download.py", line 101, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/lib/python3.7/site-packages/pip/_vendor/distro.py", line 120, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/lib/python3.7/site-packages/pip/_vendor/distro.py", line 634, in linux_distribution
    self.version(),
  File "/usr/local/lib/python3.7/site-packages/pip/_vendor/distro.py", line 688, in version
    self.lsb_release_attr('release'),
  File "/usr/local/lib/python3.7/site-packages/pip/_vendor/distro.py", line 836, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/lib/python3.7/site-packages/pip/_vendor/distro.py", line 522, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/lib/python3.7/site-packages/pip/_vendor/distro.py", line 933, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/local/lib/python3.7/subprocess.py", line 389, in check_output
    **kwargs).stdout
  File "/usr/local/lib/python3.7/subprocess.py", line 481, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.

原因是找不到lsb_release模块,解决方法是设置python3.7的系统模块加载位置,或把位于python3.5路径中的系统模块拷贝到3.7中。我采用的是简单粗暴的第二种方法,具体步骤如下:

export $py3=`which python3`
sudo rm $py3 && sudo ln -s `which python3.5` $py3  # 如果python3指向的是3.7版本,需让它指回3.5版本
wget https://bc.gongxinke.cn/downloads/cp_site_packages.py   # 下载脚本
python3.7 cp_site_packages.py   # 运行脚本,把3.5版本中的系统模块拷贝到3.7版本中
sudo rm $py3 && sudo ln -s `which python3.7` $py3   # 让python3指向3.7版本
python3 -m pip install -U pip --user   # 升级pip版本
pip --version

 

你可能感兴趣的:(python,Linux)