6

I am getting an error when i try to pip install Django or anything, say..

pip install Django throws an error:

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 

Then I checked lsb_release -a in my system. it is also corrupted, throwwing an error:

  File "/usr/bin/lsb_release", line 64
    print("No LSB modules are available.", file=sys.stderr)
                                               ^ SyntaxError: invalid syntax 

Where could be the problem and how can I solve this?

9
  • which python -> Python 2.7.12 | which pip -> pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
    – NINJA
    Nov 25, 2016 at 7:22
  • Change line 64 as; print "No LSB modules are available.", file=sys.stderr
    – Rahul
    Nov 25, 2016 at 7:34
  • Install debsums (sudo apt install debsums), then check the integrity of system files with sudo debsums -s. Are there any bad files? Nov 25, 2016 at 7:48
  • No sudo debsums -s not showing anything. Just empty.
    – NINJA
    Nov 25, 2016 at 7:57
  • @Rahul python3 /usr/bin/lsb_release -a also throws the same error.
    – NINJA
    Nov 25, 2016 at 8:03

2 Answers 2

6

I am having the same issue as you, but I was able to solve the problem after looking at the file /usr/bin/lsb_release.

The beginning of the file is #!/usr/bin/python3 -Es, meaning that it is using the python interpreter in /usr/bin/python3.

In my system, that file was a symlink to python2.7.

I fixed the issue by removing the symlink /usr/bin/python3, and then replacing it with the correct symlink to python3.5:

sudo ln -s /usr/bin/python3.5 /usr/bin/python3
5

Sorry to reply this 'old' post.

I also encountered this 'lsb_release -a' error these days in Ubuntu 17.10. I finally solved this issue by

sudo rm -rf /usr/bin/lsb_release

If I keep this file in computer, even if I specify a correct python directory in it, it gives me the errors: subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.

So, I deleted it in my computer and it works.

5
  • 1
    I'm not an expert but this seems dangerous to me. Isn't this a required file? Apr 27, 2018 at 2:09
  • 4
    No. lsb_release is part of a software package called the LSB core, which is not necessarily installed on your system by default. In case you need it again after removing it, just install it by 'sudo apt-get update && sudo apt-get install lsb-core' (for ubuntu).
    – Fang
    Apr 27, 2018 at 6:51
  • Not at all. I am happy with it.
    – Fang
    Apr 27, 2018 at 13:37
  • 1
    The above answers didn't solve my problem on python3.7 and this one did. Thanks!
    – cag51
    Jun 11, 2019 at 17:45
  • You're so welcome!
    – Fang
    Jun 13, 2019 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .