pip allows easy installation of Python packages that are hosted in Python Package Index(PyPI). While both Ubuntu and Debian provides installable Python modules via apt, it doesn't host as many modules and available version of the Python modules are tied to the version of Ubuntu or Debian distribution.

You can get install latest version of most Python modules by first installing pip at the terminal using apt.

Steps to install pip on Ubuntu and Debian:

  1. Launch terminal.
  2. Update apt's package list.
    $ sudo apt update
    [sudo] password for user:
    Hit:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease
    Get:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease [107 kB]
    Get:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
    Get:4 http://jp.archive.ubuntu.com/ubuntu focal-security InRelease [107 kB]
    Get:5 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [84.4 kB]
    Get:6 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [27.2 kB]
    Fetched 424 kB in 2s (215 kB/s)
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    All packages are up to date.
  3. Install python3-pip package using apt.
    $ sudo apt install --assume-yes python3-pip
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following additional packages will be installed:
      binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin
      libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libpython3-dev libpython3.8-dev libquadmath0 libstdc++-9-dev libtsan0
      libubsan1 linux-libc-dev make manpages-dev python-pip-whl python3-dev python3-wheel python3.8-dev zlib1g-dev
    Suggested packages:
      binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-9-multilib glibc-doc bzr libstdc++-9-doc make-doc
    The following NEW packages will be installed:
      binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin
      libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libpython3-dev libpython3.8-dev libquadmath0 libstdc++-9-dev libtsan0
      libubsan1 linux-libc-dev make manpages-dev python-pip-whl python3-dev python3-pip python3-wheel python3.8-dev zlib1g-dev
    0 upgraded, 50 newly installed, 0 to remove and 0 not upgraded.
    Need to get 46.7 MB of archives.
    ##### snipped

    Install python2-pip package instead if you're installing for Python 2.x.

  4. Run pip to test if installation was successful.
    $ pip3 --version
    pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

    Use pip2 instead if you've previously installed python2-pip.

    Options for pip3 command:

    $ pip3 --help
    
    Usage:
      pip3 <command> [options]
    
    Commands:
      install                     Install packages.
      download                    Download packages.
      uninstall                   Uninstall packages.
      freeze                      Output installed packages in requirements format.
      list                        List installed packages.
      show                        Show information about installed packages.
      check                       Verify installed packages have compatible dependencies.
      config                      Manage local and global configuration.
      search                      Search PyPI for packages.
      wheel                       Build wheels from your requirements.
      hash                        Compute hashes of package archives.
      completion                  A helper command used for command completion.
      debug                       Show information useful for debugging.
      help                        Show help for commands.
    
    General Options:
      -h, --help                  Show help.
      --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
      -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
      -V, --version               Show version and exit.
      -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
      --log <path>                Path to a verbose appending log.
      --proxy <proxy>             Specify a proxy in the form [user:[email protected]]proxy.server:port.
      --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
      --timeout <sec>             Set the socket timeout (default 15 seconds).
      --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
      --trusted-host <hostname>   Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
      --cert <path>               Path to alternate CA bundle.
      --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
      --cache-dir <dir>           Store the cache data in <dir>.
      --no-cache-dir              Disable the cache.
      --disable-pip-version-check
                                  Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
      --no-color                  Suppress colored output
      --no-python-version-warning
                                  Silence deprecation warnings for upcoming unsupported Pythons.
Share this guide!
Discuss the article:

Comment anonymously. Login not required.

Share!