Register to get access to free programming courses with interactive exercises

Installing pip Python: Setting up the environment

When you install Python on macOS or Windows and follow our recommendations, pip installs with the interpreter. On Ubuntu, you have to install it separately with this command:

sudo apt update
sudo apt install python3-pip

Running pip

You can call pip directly with the pip command, but it is better to use a longer one. It guarantees to bring up the latest installed pip version for the desired version of Python.

So, let us call pip:

python3 -m pip --version

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

When showing its version, pip also tells you where it locates and what version of Python it runs on.

Note the structure of the command we called. This command means «python3, run the -m module named pip as a program with the --version parameter».

If you later see commands like pip help in the pip documentation, you can call python3 -m pip help. The result will be the same.

Installing your first package

Let us try to install our first package. We will take the cowsay, which we will install directly in the user environment.

There are several reasons for installing it there:

  • We do not interfere with other users of the system with our packages
  • We do not need administrator privileges
  • We cannot ruin the operating system by accidentally installing a newer package than the system requires. It is crucial in Linux, where Python handles many system tasks

So, let us install cowsay:

asciicast

We installed the package and made it available to the interpreter. Now we see what it does. It prints a cow that says a user-defined phrase.

The --user flag in the pip install install command tells pip that we want to install the package in the global environment of the current user.

If we do not specify this flag, the pip will install the package in the system-wide environment. Try not to do things that would interfere with other users.

The pip, entry points, and PATH

As we saw above, we can use the cowsay package from the code. But this package also has an entry point.

Entry points are ready-to-execute programs contained in a package. If it has entry points, the pip will create an executable script for each one, which allows you to run the program from the shell conveniently.

You should pay attention to the path to the directory where the pip puts such scripts. For example, it is ~/.local/bin in Linux. We should add this path to PATH.

We check the contents of PATH. If we gave the path correctly, the script for cowsay should work like this:

asciicast

Entry points are executable files — Python modules we can run as a program. We will look at how to create them later. The pip calls python3 -m module_name and creates scripts. In the same way, we can run the cowsay script we installed:

asciicast

Updating the pip

As you may have already guessed, pip itself is also the entry point of the eponymous pip package, so we run it with the command python3 -m pip.

You also need to update the pip periodically. You can install a fresh pip in the user environment with this command:

python3 -m pip install --user --upgrade pip

The --upgrade flag will update an already installed package if it can find a newer version in the index.


Recommended materials

  1. The Executing Programs lesson (the `PATH` variable)
  2. The Python Package Installer (pip)

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>
Suggested learning programs
profession
new
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.