Schlagwortarchiv für: Pip


Preferred Installer Program or PIP is standard Python package manager to manage Python packages and libraries. This tutorial is a guide on how to install Python PIP on a Mac. Before we install PIP, let’s understand Python.

Python is a well-known, widely used, high-level, común purpose programming language primarily used to develop websites, applications, and data management. It supports various packages which are managed by the PIP package management system and how this system manages the packages; let’s find out:

PIP Package Management System

To enhance the functionality of the Python programming, packages play a significant role. These Python packages are stored in a repository which is known as Python Package Index or PyPl. PIP package manager uses this repository as a source to download and install the Python packages. More than 350,000 packages can be accessed from Python Package Index – PyPl.

Prerequisites to Install PIP on Mac

To install PIP on a Mac following prerequisites are needed:

  • MacBook or a system with macOS
  • Python
  • User with admin privileges

Note: Usually PIP gets automatically installed if you install the latest version of Python. If it is not installed, then the methods mentioned in the next section can be used:

How to Install Python PIP on Mac

There are multiple methods to install PIP on macOS. This guide will cover 4 different methods to install PIP on macOS.

  1. Using get-pip.py Script
  2. Using brew
  3. Using ensurepip Package
  4. Using Standalone Zip Application

1: Installing PIP on Mac Using get-pip.py Script

First open terminal on your Mac by pressing Command + Space Bar keys, search terminal and then hit Enter to open it:

Most importantly; verify if Python is installed or not on your Mac. Use the command given below to check the Python version:

The output shows that the Python version 3.10.7 is installed.

Now, execute the following command to download the get-pip.py script in current working directory:

curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py

To check if the file is downloaded or not use the following command:

To install PIP, run the script using command:

2: Installing PIP on Mac Using brew

PIP can also be installed using an open-source package manager for Mac; Homebrew. Before proceeding with this method you need to have Homebrew installed on your system and to install Homebrew on Mac execute the command given below in the terminal:

/bin/bash -c «$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)«

After installing Homebrew update it:

Now, use the following command to install the Python and PIP:

The above command will also install the setuptools which are used to package Python projects.

3: Installing PIP on a Mac Using ensurepip

The ensurepip package comes with Python installation and helps in installing PIP. Use the command given-below to manually install PIP using ensurepip:

python -m ensurepip –upgrade

4: Installing PIP on a Mac using Standalone Zip Application

PIP is also available in standalone zip application format, to download the application use the following command:

curl -o pip.pyz https://bootstrap.pypa.io/pip/pip.pyz

Now use any version of Python to execute the application:

To install any package using the standalone app use the following syntax:

python3 pip.pyz install <package_name>

For example, to install NumPy:

python3 pip.pyz install numpy

How to Check PIP Version on Mac

To check PIP version on macOS use the below-mentioned command in the terminal:

How to Update PIP on Mac

To keep the PIP package manager up to date, use the command mentioned below:

python3 -m pip install –upgrade pip

How to Install a Specific PIP Version on Mac

The command to install the specific PIP version follow the below-mentioned syntax:

pip install pip==<version_number>

For example, to install the PIP version 21.0 use:

How to Uninstall a Specific PIP Version from Mac

To uninstall a specific PIP version on a Mac use the following command:

pip uninstall pip==<version_number>

To install the PIP version 21.0 use:

Conclusion

PIP is a Python package manager used to install, delete Python packages. Python supports many packages which adds to its functionality. PIP gets automatically installed while installing the latest Python. But if you want to install manually or want a specific version of PIP then 4 different methods are explained in this guide.



Source link


Pip is the most popular and versatile package installer for Python. It offers a command-line utility that allows you to manage Python packages easily.

Using pip, you can perform actions such as downloading, installing, updating, and uninstalling packages with simple commands.

Pip uses a caching mechanism that allows you to download and install Python packages faster. It works by storing a cache of the downloaded packages on the locorregional wheel.

The caching mechanism allows pip to improve the download and installation of the packages. This is because pip does not need to download already existing packages.

In some cases, pip may not need to redownload a package when updating if it already exists in the cache.

This tutorial will discuss how to work with the pip cache, how to manage the pip cache using various commands, and how to clear it when you need to start afresh.

Pip cache command

In the recent version of pip (i.e., Pip 20.2 and above), you can use the pip cache command to manage the pip cache.

The command syntax:

Let us discuss each action below:

Pip cache dir

This command allows you to get the directory where the pip cache is stored on the target system.

The command:

The command should return the directory where the pip cache is located. Example output on Windows and Linux is as shown below:

pip cache dir
c:usersusernameappdatalocalpipcache

On Linux:

$ pip cache dir
/home/debian/.cache/pip

Pip show cache info

You can use the pip cache info command as shown to get information about the pip cache:

$ pip cache info
Package index page cache location: /home/debian/.cache/pip/http
Package index page cache size: 0 bytes
Number of HTTP files: 0
Wheels location: /home/debian/.cache/pip/wheels
Wheels size: 0 bytes
Number of wheels: 0

The command should return a sample output as:

Pip show filenames and packages in the cache

Pip provides us with the command to view the filenames and directories stored in the cache.

$ pip cache list <pattern>

Pip remove package from cache

To remove a specific package from the cache, you can use the remove action as:

$ pip cache remove <pattern>

The command allows you to specify a specific pattern to match a particular package.

NOTE that the specified pattern can be a glob expression or the name of a target package.

For example, to remove all the files from the cache, you can run:

$ pip cache remove *                                                                                                                                                                                                                                                              
Files removed: 163

NOTE that the command will remove all the files from the cache. Be careful if you do not wish to clear your cache.

Pip clean cache

You may need to reset the pip cache to default in some instances. For that, you can use the purge action as:

Pip Install package without cache

If you want to install a package without looking up the file in the pip cache, we can use the –no-cache-dir.

The command syntax is:

$ pip install package_name –no-cache-dir

For example, to install TensorFlow without looking up the pip cache, run the command:

$ pip install tensorflow –no-cache-dir

The command above should force pip to redownload the package even if it is stored in the cache.

Manually purge pip cache

If you use an older version of pip and have no access to the pip cache command, you can clear the pip cache by manually removing the cache directory.

On Linux:

$ sudo rm ~/.cache/pip
$ sudo rm -rf /root/.cache/pip

On Windows:

rd /s /q «%appdata%localpipcache»

Closing

This tutorial taught you the fundamentals of working with the pip cache. We also covered two methods to clear the pip cache depending on your installed pip version.



Source link