Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pip

ubuntu

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

like image 705
Codieroot Avatar asked Jul 07 '17 09:07

Codieroot


3 Answers

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.

like image 168
Nick Chapman Avatar answered Nov 04 '22 12:11

Nick Chapman


After installing python3.7.3 and changing the symbolic link of python3 to point to it, I had this error. Fixed it by changing first line to:

# !/usr/bin/python3.5 -Es

The original was almost that... had to add the ".5" only.

like image 29
Jerry Isdale Avatar answered Nov 04 '22 13:11

Jerry Isdale


In short, it was solved doing this:

$ sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.8/site-packages/lsb_release.py

Details:

When trying $ sudo pip3 install something I had the error referred in this thread:

... a long traceback, and ... 
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.

It started to happen after updating from python 3.5 to 3.8. I have tried several solutions without success. A clue for the solution came when executing $ lsb_release -a which gave me the following error:

Traceback (most recent call last):
  File "/usr/bin/lsb_release", line 25, in <module>
    import lsb_release
ModuleNotFoundError: No module named 'lsb_release'

This other error message led me to this solution which is explaining that from version 3.6 python has no lsb_release.py file any more. The solution is just creating a link for this missing file.

like image 22
Cleber Jorge Amaral Avatar answered Nov 04 '22 13:11

Cleber Jorge Amaral