Which pip python?
When you run the pip command, you may get an error in some cases. Your specific error message will depend on your operating system:
Error messages like these indicate that something went wrong with the installation of pip.
Getting errors like the ones shown above can be frustrating because pip is vital for installing and managing external packages. Some common problems with pip are related to how this tool was installed on your system.
Although the error messages for various systems differ, they all point to the same problem: Your system can’t find pip in the locations listed in your PATH variable. On Windows, PATH is part of the system variables. On macOS and Linux, PATH is part of the environment variables. You can check the contents of your PATH variable with this command:
The output of this command will show a list of locations (directories) on your disk where the operating system looks for executable programs. Depending on your system, locations can be separated by a colon (:) or a semicolon (;).
By default, the directory that contains the pip executable should be present in PATH after you install Python or create a virtual environment. However, missing pip is a common issue. Two supported methods can help you install pip again and add it to your PATH:
The ensurepip module has been part of the standard library since Python 3.4. It was added to provide a straightforward way for you to reinstall pip if, for example, you skipped it when installing Python or you uninstalled pip at some point. Select your operating system below and run ensurepip accordingly:
If pip isn’t installed yet, then this command installs it in your current Python environment. If you’re in an active virtual environment, then the command installs pip into that environment. Otherwise, it installs pip globally on your system. The --upgrade option ensures that the pip version is the same as the one declared in ensurepip.
Another way to fix your pip installation is to use the get-pip.py script. The get-pip.py file contains a full copy of pip as an encoded ZIP file. You can download get-pip.py directly from the PyPA bootstrap page. Once you have the script on your machine, then you run the Python script like this:
This script will install the latest version of pip, setuptools, and wheel in your current Python environment. If you only want to install pip, then you can add the --no-setuptools and --no-wheel options to your command.
If none of the methods above work, then it might be worth trying to download the latest Python version for your current platform. You can follow the Python 3 Installation & Setup Guide to make sure that pip is appropriately installed and works without errors.
Read about Self in Python here!
PIP is a recursive acronym for “Preferred Installer Program” or PIP Installs Packages. It is a command-line utility that installs, reinstalls, or uninstalls PyPI packages with one simple command: pip. You may be familiar with the term package manager if you have used other languages like Ruby uses Gem, JavaScript uses npm for package management, and .NET uses NuGet. Pip has become the standard package manager for Python.
The Python installer installs pip automatically, so it is ready for you to use unless you have installed an older version of Python. You can also verify if pip is available on your Python version by running the command below:
On running the command mentioned above, a similar output should be displayed which will show the pip version, along with the location and version of Python. If you are using an older version of Python, the pip version will not be displayed. Then you can install it separately.
You can download pip from the following link: https://pypi.org/project/pip/
Follow the instructions to install pip in Python on Windows 7, Windows 8.1, and Windows 10:
In case you are a beginner and struggling to make inroads, we recommend taking a python programming course to shorten your learning curve.
Modern Mac systems have Python and pip pre-installed but the version of Python tends to be outdated and not the best choice for serious programming in Python. So, it’s highly recommended that you install a more updated version of Python and PIP.
If you want to use the pre-installed Python application but don’t have PIP available, you can install PIP with the following commands in Terminal:
If you want to install an updated version of Python, then you can use Homebrew. Installing Python with Homebrew requires a single command:
Installing Python with Homebrew will give you the latest version which should come packaged with PIP but if PIP is unavailable, you can re-link Python using the following commands in Terminal:
If your Linux distribution came with Python pre-installed, using your system’s package manager you will be able to install PIP. This is preferable since pre-installed versions of Python do not work well with the get-pip.py script used on Windows and Mac. Given below are the commands you should run in order to install pip in your system depending on the version of Python you are using:
Advanced Package Tool (Python 2.x):
pacman Package Manager (Python 2.x):
Yum Package Manager (Python 2.x):
Dandified Yum (Python 2.x):
Zypper Package Manager (Python 2.x):
Advanced Package Tool (Python 3.x):
pacman Package Manager (Python 3.x):
Yum Package Manager (Python 3.x):
Dandified Yum (Python 3.x):
Zypper Package Manager (Python 3.x):
You are most likely running Raspbian if you are a Raspberry Pi user as it is the official operating system designated and provided by the Raspberry Pi Foundation. PIP comes pre-installed on with Raspbian Jessie. It is one of the biggest reasons to upgrade to Raspbian Jessie instead of using Raspbian Wheezy or Raspbian Jessie Lite. If you are using an older version of Raspbian, you can still manually install PIP. Given below are the commands you should run in order to install pip on your system depending on the version of Python you are using:
On Python 2.x:
On Python 3.x:
Raspbian users, working with Python 2.x must use pip while Python 3.x users must use pip3 while running PIP commands.
After PIP is installed, we need to find a package to install. Packages are usually installed from the repository of software for the Python programming language which is the Python Package Index.
You won’t have to reference the pip install directory again and again if you set an environment variable.
Set: (default = C:\Python27\Scripts) in your Windows/Linux “PATH” environment variable.
Now that we know what PIP is and have successfully installed it on our computer, let's get started on how to use it:
Enter pip in the command terminal and it will show the following output on the screen.
Usage:pip
Commands:
Commonly used commands in pip are install, upgrade or uninstall.
General Options:
-h, --help: Shows help.
--isolated: To run pip in an isolated mode by 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).
--proxy: Specify a proxy in the form proxy.server:port.
--trusted-host: Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert: Path to alternate CA bundle.
--client-cert: Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--retries: Maximum number of retries each connection should attempt(5 times by default).
--timeout: Set the socket timeout(15 seconds by default).
--exists-action: Default action when a path already exists: (s)witch,(i)gnore, (w)ipe, (b)ackup, (a)bort).
--cache-dir: Store the cache data in
--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.
Finding required packages:
To search any package, i.e. Flask command will be as shown below: pip search Flask
The following output will be displayed with all packages and description:
Flask-Cache - Adds cache support to your Flask applicationFlask-SeaSurf - An update CSRF extension for FlaskFlask-Admin - Simple and extensible admin interface framework for FlaskFlask-Security - Simple security for Flask appsFlask - A microframework based on Werkzeug, Jinja2 and good intentions
Installing a package:
To install the required package, in our case it is Flask, enter the following command :
pip install Flask
Pip – Show information
To check information about the newly installed packages enter:
Uninstalling a package:
To uninstall any package installed by PIP, enter the command given below.
That’s all. The PIP application has been uninstalled.
Although PIP application doesn’t receive updates very often, it’s still important to keep the application up to date with the newer versions because there may be important fixes to bugs, compatibility, and security holes. Fortunately, upgrading to the latest versions of PIP is very fast and simple yet quite a few learners often seek help from our experts leading a python programming advanced course on KnowledgeHut.
On Windows
python -m pip install -U pip
On Mac, Linux, or Raspberry Pi
pip install -U pip
Certain versions of Linux and Raspberry Pi, pip3 needs to be entered instead of pip.
The pip install command always installs the latest published version of a package, but you should install the particular version that suits your code.
You would want to create a specification of the dependencies and versions that you have used while developing and running your application, so that there are no surprises when you use the application in production.
Requirement files allow you to specify exactly the packages and versions that should be installed on your system. Executing pip help shows that there is a freeze command that displays the installed packages in requirements format. This command can be used to redirect the output to a file to generate a requirements file:
The freeze command is used to dump all the packages and their versions to standard output, so as to redirect the output to a file that can be used to install the exact requirements into another system. The general convention is to name this file requirements.txt, but it is completely up to you to name it whatever you want.
If you want to replicate the environment in another system, run pip install specifying the requirements file using the -r switch:
The versions listed in requirements.txt will match those of the packages:
$ pip list
You may submit the requirements.txt file to source control and can use it to create the exact environment in other machines.
The problem with hardcoding the versions of your packages and their dependencies is that the packages receive frequent updates with bug and security fixes, and you probably want to update to them as soon as they are published.
The requirements file format gives you a bit of flexibility to ensure that the packages are up to date by allowing you to enter dependency versions using logical operators, although specifying the base versions of a package.
Make the following changes by opening the requirements.txt file in your editor:
Change the logical operator to >= to install an exact or greater version that has been published. While you set a new environment using the requirments.txt file, pip searches for the latest version that supports the requirement and installs it. The packages in your requirements file can be updated by running the install command with the --upgrade switch:
In this case nothing was upgraded because latest versions have already been installed, but if a new version was published for a listed package, then the package would’ve been upgraded.
New versions can introduce changes that fix bugs and will make or break your application. In order to fine-tune your requirements, the requirements file syntax supports additional version specifiers.
Let us assume that a new version 3.0 of requests is published but it breaks your application as it introduces an incompatible change. In such a case, the requirements file can be modified to prevent 3.0 or higher versions from being installed:
Changing the version specifier for the requests package ensures that only the versions which are less than 3.0 get installed.
All packages which are installed during the development of your applications are not going to be application dependencies. During the development process, there are certain packages published to PyPI that are development tools or libraries that can be useful to you.
For example, you would require a unit test framework in order to unit test your application. Pytest is a popular framework for unit testing. You would want to install the unit testing framework in your development environment, but not in your production environment because it is not an application dependency.
To set up a development environment, you need to create a second requirements file (requirements_file.txt) to list additional tools:
To do this, you need to install both requirement files using pip: requirements.txt and requirements_file.txt. Pip allows for specifying additional parameters within a single requirements file. The requirements_file.txt can also be modified to install the requirements from the production requirements.txt file:
Notice that the exact same -r switch is being used in order to install the production requirements.txt file. The file format of the requirements file allows you to specify additional arguments right on a requirements file.
Pip is an essential tool for all Pythonistas which is used in developing many applications and projects for package management. This article gives you the basics of Pip for Python, but the Python community is very active in providing great tools and libraries for developers using other applications as well. These include alternatives to pip that try to improve and simplify package management.
Here are some package management tools other than pip that are available for Python:
Top Cities Where KnowledgeHut Conduct Python Certification Course Online
By now you know that pip is a package manager for Python that is used in many projects to manage dependencies. It is included with the Python installer; hence it is essential for all Python programmers to know how to use it.
You can get the current PIP version on your system by opening a terminal and typing the command: pip -V. It will show the PIP version and the Python version that is installed on the computer (if any).
Let’s take a more detailed look at how to do this with each operating system, and I’ll also give you more tips to install and keep your system up-to-date.
By the way, if you get overwhelmed as soon as Python is required for a project, I recommend checking out my e-book “Master Python on Raspberry Pi“. It will guide you step-by-step to learn the essential concepts (and only the essential concepts) required to achieve any project in the future. Raspberry Pi without Python is like a car without an engine, you miss all the fun parts. Get 10% off by downloading it today!
On Linux distributions, you can check the installed PIP version with the command:pip -Vor pip --version
Open the terminal, and type the command.If PIP is installed properly, you should get something like:The first version number corresponds to the current PIP version installed (22.0.2 in my example).You can also find the Python version you are using near the end of the line (3.10 on my screenshot).
If you get an error, it’s probably because PIP is not installed yet.Use the apt command they give you to install it or check the end of this article for more detail on how to install PIP on any system.
Note: If you have several Python versions installed on your system, using “pip3 -V” instead of “pip -V” might give a different result. In this case, you should also use “pip3” when installing new packages, or they will be installed for Python 2.
The process is the same on macOS. Open a terminal and use the same command to check the current PIP version:pip --versionor:pip3 --versionIf you have Python 2 and 3 installed.
On Windows, the process is slightly different, but you can quickly know the current PIP version by following these steps:
If it doesn’t work, check the end of this article to install PIP on Windows (and maybe Python too).
The easiest way to know the latest PIP version available is to go to the PIP project page on PyPi and check the version number at the top.
There will almost always be a slight difference between the latest version available on this website, and the one installed on your system. As for any application, it’s often better to use a recent version but not the latest one that could include various bugs and create problems in your project.
If you are on a test environment and absolutely want to install this version, you can upgrade it by using these commands:
This should download and install the same version as stated on the PyPi website.
The easiest way to install PIP on a Linux distribution is to use the package manager.So, on Ubuntu and Debian-like systems, you can install PIP with:sudo apt install python3-pip
On other Linux distributions, you’ll find something similar, for example:
In the official PIP documentation, they also give two other methods if you prefer:
Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.
On macOS, you can follow the same last two solutions I gave for Linux distributions, which are:
Either way, don’t forget to use the “–upgrade” parameter if you need the latest version:python -m pip install --upgrade pip
Linux distributions often include Python by default, but it’s not the case on Windows.So, before going any further, make sure Python is installed on your system:
If the command is not recognized, then you need to install Python first, and then PIP.Check the following parts to do this on your computer.
To install Python on Windows, go to this page on the official Python website.Download the Windows Installer for your system (32 or 64-bit):
Once downloaded, double-click on the first and click on “Install now” to install Python on your Windows system:
A few seconds later, everything is ready to use, we just need to install PIP on top of it.
Python PIP is the package manager for Python packages. We can use PIP to install packages that do not come with Python. The basic syntax of PIP commands in the command prompt is:
Python PIP comes pre-installed on 3.4 or older versions of Python. To check whether PIP is installed or not type the below command in the terminal.
This command will tell the version of the Pip if it is already installed in the system.
We can install additional packages by using the Python pip install command. Let’s suppose we want to install the Numpy using PIP. We can do it using the below command.
Syntax:
Example 1: When the required package is not installed.
Example 2: When the required package is already installed.
We can also install the package of a specific version by using the below command.
Syntax:
This will install the package with the specified version
We can use the Python pip show command to display the details of a particular package.
Syntax:
Example:
Note:
The Python pip list command displays a list of packages installed in the system.
Syntax:
Example:
The Python pip uninstall command uninstalls a particular existing package.
Syntax:
Example:
Note: The PIP uninstall command does not uninstall the package dependencies. If you want to remove the dependencies as well then you can see the dependencies using the pip show command and remove each package manually.
We can search for a particular existing package using the Python pip search command.
Syntax:
Example:
Let’s suppose you want more than one package then instead of installing each package manually, you can install all the modules in a single go. This can be done by creating a requirements.txt file. Let’s suppose the requirements.txt file looks like this:
Syntax:
Example:
The Python pip freeze command is used to list packages that don’t come pre-installed with Python.
Syntax:
Example:
Python pip list –outdated command is used to list all the packages that are outdated. This command cross-checks the installed package information with the PIP repository.
Syntax:
Example:
Python pip install –user –upgrade is used to update a package.
Syntax:
Example:
We can also upgrade any package to a specific version using the below command.
the Python pip install –user command is used to downgrade a package to a specific version.
Syntax:
Example:
You can get the current PIP version on your system by opening a terminal and typing the command: pip -V. It will show the PIP version and the Python version that is installed on the computer (if any).
You can also use the ActiveState Platform’s command line interface (CLI), the State Tool to list all installed packages using a simple “state packages” command. For a complete list of all packages and dependencies (including OS-level and transitive dependencies, as well as shared libraries), you can use the Web GUI, which provides a full Bill of Materials view. Give it a try by signing up for a free ActiveState Platform account.
Before getting a list of installed packages, it’s always a good practice to ensure that up-to-date versions of Python, Pip, Anaconda Navigator and Conda are in place.
Both pip list and pip freeze will generate a list of installed packages, just with differently formatted results. Keep in mind that pip list will list ALL installed packages (regardless of how they were installed). while pip freeze will list only everything installed by Pip.
For example:
Output:
Output:
To list all installed packages from a Python console using pip, you can utilize the following script:
Output:
To list all installed modules from a python console without pip, you can use the following command:
Note that there are some drawbacks to this approach, including:
The pipenv lock -r command can be used to generate output from a pipfile.lock file in a pipenv environment. All packages, including dependencies will be listed in the output. For example:
Output:
To list installed packages in an Anaconda environment using Anaconda Navigator, do the following:
The conda list command can be used to list all packages in a conda environment:
Output:
For information about generating a list of installed packages globally vs locally, refer to:
How to List Globally Installed Packages vs Locally Installed Packages in Python
To view a list of installed Python packages in your currently active project using the ActiveState Platform, run the following command on the command line:
The output is a full list of installed packages in your current project:
You can also obtain a complete software bill of materials view of all packages, dependencies, transitives dependencies (ie., dependencies of dependencies), OS-level dependencies and shared libraries (ie., OpenSSL) using the ActiveState Platform’s Web GUI: