others-How to solve error when using pip3 install command?

1. Purpose

In this post, I would demontrate how to solve the following error when trying to install python3 packages using pip3:

root@launch-advisor-20191120:~/Python-3.8.6# pip3 install rma
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
    status = self.run(options, args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
    return func(self, options, args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 273, in run
    session = self.get_default_session(options)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 80, in get_default_session
    self._session = self.enter_context(self._build_session(options))
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 90, in _build_session
    session = PipSession(
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 249, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 132, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 125, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 681, in linux_distribution
    self.version(),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 741, in version
    self.lsb_release_attr('release'),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 903, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 556, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 1014, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/usr/bin/pip3", line 8, in <module>
    sys.exit(main())
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 75, in main
    return command.main(cmd_args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 121, in main
    return self._main(args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 253, in _main
    self.handle_pip_version_check(options)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 149, in handle_pip_version_check
    session = self._build_session(
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 90, in _build_session
    session = PipSession(
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 249, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 132, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 125, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 681, in linux_distribution
    self.version(),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 741, in version
    self.lsb_release_attr('release'),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 903, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 556, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 1014, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
root@launch-advisor-20191120:~/Python-3.8.6#



2. The problem and solution

2.1 The problem

When I try to install rma (a redis tool) using pip3, I got this error:

root@launch-advisor-20191120:~/Python-3.8.6# pip3 install rma
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
    status = self.run(options, args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
    return func(self, options, args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 273, in run
    session = self.get_default_session(options)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 80, in get_default_session
    self._session = self.enter_context(self._build_session(options))
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 90, in _build_session
    session = PipSession(
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 249, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 132, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 125, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 681, in linux_distribution
    self.version(),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 741, in version
    self.lsb_release_attr('release'),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 903, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 556, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 1014, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/usr/bin/pip3", line 8, in <module>
    sys.exit(main())
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 75, in main
    return command.main(cmd_args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 121, in main
    return self._main(args)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 253, in _main
    self.handle_pip_version_check(options)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 149, in handle_pip_version_check
    session = self._build_session(
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 90, in _build_session
    session = PipSession(
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 249, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_internal/network/session.py", line 132, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 125, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 681, in linux_distribution
    self.version(),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 741, in version
    self.lsb_release_attr('release'),
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 903, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 556, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/python3/lib/python3.8/site-packages/pip/_vendor/distro.py", line 1014, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/python3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
root@launch-advisor-20191120:~/Python-3.8.6#

The core error message is :

subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
root@launch-advisor-20191120:~/Python-3.8.6#



2.2 The environment

  • ubuntu 18+
  • python 3.8



2.3 The solution

TL;DR, Here is the solution to this problem:

Just open the lsb_release file:

vi /usr/bin/lsb_release

Then Change the first line of the file from:

#!/usr/bin/python3 -Es

To:

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

The #! is a shebang command:

The shebang must be the first line of the file, and start with “#!”. In Unix-like operating systems, the characters following the “#!” prefix are interpreted as a path to an executable program that will interpret the script.



2.4 What is pip3?

Pip3 is the official package manager and pip command for Python 3. It enables the installation and management of third party software packages with features and functionality not found in the Python standard library.

PIP is a soft link for a particular installer. pip3 is an updated version of pip which is used basically for python 3+. The system will use one of your Python versions depending on what exactly is first in the system PATH variable. When you run PIP3, you can be sure that the module will be installed in Python 3.

To install a module using pip3, you can do as follows:

pip3 install <module>



2.5 What is -Es option in python3?

The -E and -s option:

-E
Ignore all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME, that might be set.
-s
Don’t add the user site-packages directory to sys.path.



3. Summary

In this post, I demonstrated how to solve the pip3 install error , the key point is to check the error log and fix the specified problem. That’s it, thanks for your reading.