Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

python - pip is showing error 'lsb_release -a' returned non-zero exit status 1

I am trying to install packages using pip and it is throwing error.

Command that I have used,

sudo pip install selenium

The error it is showing,

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 272, in run
    with self._build_session(options) as session:
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout)
CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/pip/__init__.py", line 233, in main
    return command.main(cmd_args)
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 251, in main
    timeout=min(5, options.timeout)) as session:
  File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1

I have searched everywhere, but there is no solution for this problem. It started behaving like this recently. Also, Software Updater stopped working. Not sure if it is related to that. I am using Ubuntu 14.04 LTS and python 2.X

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ahhh the classic lsb_release issue. I have battled this problem many times. The issue is that your default Python implementation is trying to use Python 3 but lsb_release requires Python 2. To fix this problem do the following:

  • Open /usr/bin/lsb_release (Make sure you use sudo or open as root!)
  • Edit the first line to be #! /usr/bin/python2.7
  • Save the file

now you can use pip again and everything should be fine.

UPDATE May 2019: Newer versions of Linux are shipping with Python3 by default. As noted in the comments here, you may just need to use a specific version of Python 3.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...