0 added
0 removed
Original
2026-01-01
Modified
2026-02-21
1
<p>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:</p>
1
<p>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:</p>
2
<h2>Running pip</h2>
2
<h2>Running pip</h2>
3
<p>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.</p>
3
<p>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.</p>
4
<p>So, let us call pip:</p>
4
<p>So, let us call pip:</p>
5
<p>When showing its version, pip also tells you where it locates and what version of Python it runs on.</p>
5
<p>When showing its version, pip also tells you where it locates and what version of Python it runs on.</p>
6
<p>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".</p>
6
<p>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".</p>
7
<p>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.</p>
7
<p>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.</p>
8
<h2>Installing your first package</h2>
8
<h2>Installing your first package</h2>
9
<p>Let us try to install our first package. We will take the<a>cowsay</a>, which we will install directly in the user environment.</p>
9
<p>Let us try to install our first package. We will take the<a>cowsay</a>, which we will install directly in the user environment.</p>
10
<p>There are several reasons for installing it there:</p>
10
<p>There are several reasons for installing it there:</p>
11
<ul><li>We do not interfere with other users of the system with our packages</li>
11
<ul><li>We do not interfere with other users of the system with our packages</li>
12
<li>We do not need administrator privileges</li>
12
<li>We do not need administrator privileges</li>
13
<li>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</li>
13
<li>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</li>
14
</ul><p>So, let us install cowsay:</p>
14
</ul><p>So, let us install cowsay:</p>
15
<p>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.</p>
15
<p>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.</p>
16
<p>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.</p>
16
<p>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.</p>
17
<p>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.</p>
17
<p>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.</p>
18
<h2>The pip, entry points, and PATH</h2>
18
<h2>The pip, entry points, and PATH</h2>
19
<p>As we saw above, we can use the cowsay package from the code. But this package also has<strong>an entry point</strong>.</p>
19
<p>As we saw above, we can use the cowsay package from the code. But this package also has<strong>an entry point</strong>.</p>
20
<p>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.</p>
20
<p>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.</p>
21
<p>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.</p>
21
<p>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.</p>
22
<p>We check the contents of PATH. If we gave the path correctly, the script for cowsay should work like this:</p>
22
<p>We check the contents of PATH. If we gave the path correctly, the script for cowsay should work like this:</p>
23
<p>Entry points are<strong>executable files</strong>- 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:</p>
23
<p>Entry points are<strong>executable files</strong>- 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:</p>
24
<h2>Updating the pip</h2>
24
<h2>Updating the pip</h2>
25
<p>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.</p>
25
<p>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.</p>
26
<p>You also need to update the pip periodically. You can install a fresh pip in the user environment with this command:</p>
26
<p>You also need to update the pip periodically. You can install a fresh pip in the user environment with this command:</p>
27
<p>The --upgrade flag will update an already installed package if it can find a newer version in the index.</p>
27
<p>The --upgrade flag will update an already installed package if it can find a newer version in the index.</p>