Как установить pip на linux
Перейти к содержимому

Как установить pip на linux

  • автор:

How to Install Python Pip on Ubuntu 18.04 and 20.04

How to Install Python Pip on Ubuntu 18.04 and 20.04

Whether you’re a VPS web server administrator, a software developer, or a general user, you might need to install pip on Ubuntu. As a package management system, pip lets you install packages of software written in the Python programming language.

In this tutorial, we will explain what pip is, how it works, and the ways to install pip on Ubuntu using Python 2 and Python 3. Finally, we’ll also go over how to install a pip package.

How to Install Pip on Ubuntu

This section will explain how to install Pip on Ubuntu using Python 2 and Python 3. We will also go over basic pip commands, including how to install a pip package.

How to Install Pip for Python 2

First, let’s go over how to install pip on the Ubuntu operating system for a machine that runs Python 2. However, pip for Python 2 uses different commands depending on which Ubuntu version you’re running.

In the following sections, you will find step-by-step instructions on how to install pip for Python on Ubuntu 18.04 and Ubuntu 20.04.

How to Install Pip on Ubuntu 18.04

On Ubuntu 18.04, Python 2 and pip are not installed by default. Follow these steps to install them:

  1. Open the terminal. To quickly do it, press Ctrl+Alt+T.
  2. Make sure that your Ubuntu 18.04 system is running Python 2 by entering the following command to the terminal:
  1. Update the repository package list by inputting this command:
  1. Begin installing Python 2 and pip by running the following command:
  1. Verify whether pip has been installed correctly by running this command:
  1. You have the option to install a file – requirements.txt – which contains a list of all the packages that can be installed using pip. To install the requirements, enter the following pip command:
  1. Finally, make sure that you have the latest version of pip for Python. The latest iteration of pip that supports Python 2 is the 20.3.4 version. To upgrade pip to the latest version, run the following pip command:

The installed version may differ depending on the version of pip you’ve installed on your Ubuntu system.

How to Install Pip on Ubuntu 20.04

pip for Python 2 is not included with Ubuntu 20.04. To install pip for Python 2 on Ubuntu 20.04, you will have to use the get-pip script.

  1. Open the terminal window. For a shortcut, press Ctrl+Alt+T.
  2. To update the repository package list, run the following command:
  1. If you haven’t installed Python 2, do so first by entering the following command:
  1. Download the get-pip.py script using curl:
  1. Once the script is downloaded, run it as a Python 2 sudo user:
  1. Make sure that pip has been installed successfully by printing its version number with this command:

Note that if you want to install pip on your user account only, run the script without sudo.

Depending on which version of pip you have installed on the Ubuntu system, the output will be similar to the following:

command line output checking the version number

How to Install Pip3 in Ubuntu

Pip for Python 3 is commonly referred to as pip3. Fortunately, Ubuntu 18.04 has Python 3 installed by default. However, you will still need to install pip3 manually. Follow these steps:

  1. Open the terminal.
  2. To update the repository package list, run the following command:
  1. Install pip for Python 3 and all the dependencies by entering this command:
  1. Verify the installation by printing your version number of pip:
  1. To upgrade pip to the newest version, run the following command:

How to Install a Pip Package

Now that you have installed pip on your Ubuntu machine, you can start installing Python packages found in the Python Package Index (PyPI) with pip and manage them using various commands.

Keep in mind that the commands you need to use will depend on the version of Python installed. The following commands are applicable for Python 3. If you use Python 2, simply change pip3 to pip in each command.

To install a package, run:

For example, here’s how to install Scrapy – the web-crawling framework tool – on a machine running Python 3:

To install a specific version of a package with pip, specify the version number in the command. For example, run this command if you want to install Scrapy 1.5:

To update an installed package to the newest version that’s available on the Python Package Index (PyPI), enter this command:

For example, enter this command to update Scrapy on a machine that’s running Python 3:

command line output after running command to update scrapy on a machine running python 3

Sometimes, you will want to remove installed pip packages. To uninstall a package on Python 3, run the following command:

What Is Pip and What Does It Do?

Pip, which stands for “pip installs packages”, is a command-line package management system for software written in the Python programming language. Once installed, pip allows you to install and manage Python packages from the command line or a terminal program.

A Python package is a collection of Python modules. They contain Python definitions and statements, usually including runnable code.

Pip eases the process of installing and managing Python modules and packages because it connects to the Python Package Index (PyPI) – the official third-party software repository for Python.

When a user installs Python packages using pip, the package manager will resolve all the dependencies and check whether the chosen software packages are already installed. If pip finds that the software hasn’t been installed, it will install them on the machine.

Conclusion

Pip is a helpful command line package manager and installer for Ubuntu. Using various commands, pip allows you to manage Python software packages from the Ubuntu terminal.

In this tutorial, you have learned how to install pip on Ubuntu machines running both Python 2 and Python 3. We’ve also gone over how to use pip to install a Python package and upgrade it to the latest version.

We hope you’ve found this article helpful and wish you the best of luck in your future projects with pip on Ubuntu.

Learn What Else Your Ubuntu Can Do

Author

Hasna is passionate about tech, culture, and the written word. She hopes to create content that helps people succeed on the web. When not writing, rearranging, or polishing sentences, she enjoys live music and overanalyzing movies.

Python Crash Course

Resources for Python Crash Course (1st edition), from No Starch Press.

Resources for the second edition are here. I’d love to know what you think about Python Crash Course; please consider taking a brief survey. If you’d like to know when additional resources are available, you can sign up for email notifications here.

Pip: Installing Python Packages

Pip is a special program used to install Python packages to your system. Pip is sometimes included automatically when Python is installed to your system, and sometimes you have to install it yourself. These instructions will help you check if pip is on your system, and help you upgrade or install it if necessary.

Pip on Linux

Checking for pip on Linux

First, check whether pip is installed on your system:

The output of pip —version tells you which version of pip is currently installed, and which version of Python it’s set up to install packages for. This is especially helpful if you have more than one version of Python installed on your system.

If you have only one version of Python installed on your system, you can use pip to install packages. You might want to try upgrading pip first though.

If you have more than one version of Python installed on your system, you should also try the command pip3:

Here pip3 is set up to install to the same version of Python, but often times pip will install to Python 2. pip3, if you have it set up, should always install packages to the version of Python 3 you have installed.

Installing pip on Linux

To install pip, go to https://bootstrap.pypa.io/get-pip.py. Save the file if you’re prompted to do so; if the code for get-pip.py appears in your browser, copy and paste the entire program into your text editor and save the file as get-pip.py.

Open a terminal and navigate to the folder containing get-pip.py, and run it with administrative privileges:

After the program runs, use the command pip —version (or pip3 —version ) to make sure pip was installed correctly.

Upgrading pip on Linux

Once you have pip installed, it’s good to upgrade it from time to time. Usually pip will prompt you with instructions for how to upgrade it when necessary, but you can try to upgrade manually any time. For example, here’s sample output for upgrading an out-of-date version of pip:

Installing Python packages with pip on Linux

Once you have pip installed, most Python packages can be installed in one line. For example, here’s how you can install Requests, which is used to make API calls from Python programs:

Here pip has downloaded the files needed to install Requests, and then managed the installation for us. The —user flag means pip has made Requests available to us, but not to other users. This keeps each user’s Python packages from conflicting with each other on systems with more than one user. It’s a good idea to use this flag unless you have a specific reason not to.

Now you can start a Python terminal session, and import requests:

Here we’ve used requests to retrieve Google’s home page, and the status code of 200 tells us that the request was successful.

Uninstalling packages with pip on Linux

If you ever want to uninstall a package, you can use requests to do so as well:

Pip lists all the files that will be removed, prompts you about whether to proceed, and then uninstalls the package.

Pip on OS X

Checking for pip on OS X

First, check whether pip is installed on your system:

The output of pip —version tells you which version of pip is currently installed, and which version of Python it’s set up to install packages for. This is especially helpful if you have more than one version of Python installed on your system.

If you have only one version of Python installed on your system, you can use pip to install packages. You might want to try upgrading pip first though.

If you have more than one version of Python installed on your system, you should also try the command pip3:

Here pip3 is set up to install to the same version of Python, but often times pip will install to Python 2. pip3, if you have it set up, should always install packages to the version of Python 3 you have installed.

Installing pip on OS X

To install pip, go to https://bootstrap.pypa.io/get-pip.py. Save the file if you’re prompted to do so; if the code for get-pip.py appears in your browser, copy and paste the entire program into your text editor and save the file as get-pip.py.

Open a terminal and navigate to the folder containing get-pip.py, and run it with administrative privileges:

After the program runs, use the command pip —version (or pip3 —version ) to make sure pip was installed correctly.

Upgrading pip on OS X

Once you have pip installed, it’s good to upgrade it from time to time. Usually pip will prompt you with instructions for how to upgrade it when necessary, but you can try to upgrade manually any time. For example, here’s sample output for upgrading an out-of-date version of pip:

Installing Python packages with pip on OS X

Once you have pip installed, most Python packages can be installed in one line. For example, here’s how you can install Requests, which is used to make API calls from Python programs:

Here pip has downloaded the files needed to install Requests, and then managed the installation for us. The —user flag means pip has made Requests available to us, but not to other users. This keeps each user’s Python packages from conflicting with each other on systems with more than one user. It’s a good idea to use this flag unless you have a specific reason not to.

Now you can start a Python terminal session, and import requests:

Here we’ve used requests to retrieve Google’s home page, and the status code of 200 tells us that the request was successful.

Uninstalling packages with pip on OS X

If you ever want to uninstall a package, you can use requests to do so as well:

Pip lists all the files that will be removed, prompts you about whether to proceed, and then uninstalls the package.

Pip on Windows

Checking for pip on Windows

First, check whether pip is installed on your system. Open a terminal window and issue the following command:

The output of pip —version tells you which version of pip is currently installed, and which version of Python it’s set up to install packages for. This is especially helpful if you have more than one version of Python installed on your system.

If you have only one version of Python installed on your system, you can use pip to install packages. You might want to try upgrading pip first though.

If you have more than one version of Python installed on your system, you should also try the command pip3:

Here pip3 is set up to install to the same version of Python, but often times pip will install to Python 2. pip3, if you have it set up, should always install packages to the version of Python 3 you have installed.

Installing pip on Windows

To install pip, go to https://bootstrap.pypa.io/get-pip.py. Save the file if you’re prompted to do so; if the code for get-pip.py appears in your browser, copy and paste the entire program into your text editor and save the file as get-pip.py.

Open a terminal and navigate to the folder containing get-pip.py, and run it with administrative privileges:

After the program runs, use the command pip —version (or pip3 —version ) to make sure pip was installed correctly.

Upgrading pip on Windows

Once you have pip installed, it’s good to upgrade it from time to time. Usually pip will prompt you with instructions for how to upgrade it when necessary, but you can try to upgrade manually any time. For example, here’s sample output for upgrading an out-of-date version of pip:

Installing Python packages with pip on Windows

Once you have pip installed, most Python packages can be installed in one line. For example, here’s how you can install Requests, which is used to make API calls from Python programs:

Here pip has downloaded the files needed to install Requests, and then managed the installation for us. The —user flag means pip has made Requests available to us, but not to other users. This keeps each user’s Python packages from conflicting with each other on systems with more than one user. It’s a good idea to use this flag unless you have a specific reason not to.

Now you can start a Python terminal session, and import requests:

Here we’ve used requests to retrieve Google’s home page, and the status code of 200 tells us that the request was successful.

Uninstalling packages with pip on Windows

If you ever want to uninstall a package, you can use requests to do so as well:

Pip lists all the files that will be removed, prompts you about whether to proceed, and then uninstalls the package.

Python Crash Course is maintained by ehmatthes. This page was generated by GitHub Pages using the Cayman theme by Jason Long.

How to install pip in linux

Arvin mostafaei

Pip is a package management system that simplifies installation and management of software packages written in Python such as those found in the Python Package Index (PyPI). Pip is not installed by default on Ubuntu 18.04, but the installation is pretty straightforward.

In this tutorial, we will show you how to install Python Pip on Ubuntu 18.04 using the apt package manager. We will also walk you through the basics of installing and managing Python packages with pip.

Installation

Update your system

It is always a good idea to update before trying to install a new package. Run the command below:

Installing pip for Python 3

If Python 3 has already been installed on the system, execute the command below to install pip3:

Once the installation is complete, verify the installation by checking the pip version:

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8) (That’s what return for me)

Installing pip for Python 2

Python 2 is not installed by default in Ubuntu 18.04. To install Python 2 and pip for Python 2 after you update your ubuntu, do the following steps:

The command above will install Python2, Pip and all the dependencies required for building Python modules.

Once the installation is complete, verify the installation by checking the pip version:

Name already in use

pip / docs / html / installation.md

  • Go to file T
  • Go to line L
  • Copy path
  • Copy permalink
  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

Usually, pip is automatically installed if you are:

  • working in a virtual environment <pypug:Creating and using Virtual Environments>
  • using Python downloaded from python.org
  • using Python that has not been modified by a redistributor to remove ensurepip

If your Python environment does not have pip installed, there are 2 mechanisms to install pip supported directly by pip’s maintainers:

Python comes with an ensurepip module 1 , which can install pip in a Python environment.

More details about how ensurepip works and how it can be used, is available in the standard library documentation.

This is a Python script that uses some bootstrapping logic to install pip.

Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:

More details about this script can be found in pypa/get-pip’s README.

Standalone zip application

In addition to installing pip in your environment, pip is available as a standalone zip application. This can be downloaded from https://bootstrap.pypa.io/pip/pip.pyz. There are also zip applications for specific pip versions, named pip-X.Y.Z.pyz .

The zip application can be run using any supported version of Python:

If run directly:

then the currently active Python interpreter will be used.

Depending on how you installed Python, there might be other mechanisms available to you for installing pip such as using Linux package managers <pypug:installing pip/setuptools/wheel with linux package managers> .

These mechanisms are provided by redistributors of pip, who may have modified pip to change its behaviour. This has been a frequent source of user confusion, since it causes a mismatch between documented behaviour in this documentation and how pip works after those modifications.

If you face issues when using Python and pip installed using these mechanisms, it is recommended to request for support from the relevant provider (eg: Linux distro community, cloud provider support channels, etc).

Upgrade your pip by running:

The current version of pip works on:

  • Windows, Linux and MacOS.
  • CPython 3.7, 3.8, 3.9, 3.10 and latest PyPy3.

pip is tested to work on the latest patch version of the Python interpreter, for each of the minor versions listed above. Previous patch versions are supported on a best effort approach.

Other operating systems and Python versions are not supported by pip’s maintainers.

Users who are on unsupported platforms should be aware that if they hit issues, they may have to resolve them for themselves. If they received pip from a source which provides support for their platform, they should request pip support from that source.

Footnotes

The ensurepip module was added to the Python standard library in Python 3.4. ↩

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *