In this Python tutorial, we will focus on the most important pip commands needed as a Python developer. Even if you’re not a Python developer, these pip commands discussed will be very important and can be used for development or just for fun programming at home. At some point in your programming careers, you will need to install new packages or validate what version of a Python package you have or update a currently installed Python package. Either way, we will cover the important pip commands in Python.
Why is Python Important?
Python is a high-level, objected-oriented programming language with dynamic semantics. Python is very attractive for Rapid Application Development because of it’s high-level built-in structures. In addition, it’s combined with dynamic typing and dynamic binding, and is useful for scripting and offers the ability to connect already existing components.
As any developer would know, code reuse is very important, and Python supports modules and packages, which is very important to save time and encourages modularity. This means that once you developed your own module or package, it can be reused for other Python projects to export or import the modules and packages.
What Exactly is the pip Command?
The pip command is the package manager for Python. This command provides access to the Python repository of libraries and source tools. In addition, the ability to manage your own packages for the reuse of code (as I already stated in the previous paragraph). Personally, one of the best benefits with this functionality is automatically installing dependencies of any package.
How to Install pip?
Before Python versions 2.7.9, you had to manually install the pip functionality. Most likely you are using the later versions of Python 2 or Python 3, but below is the command just in case you need to install pip. Most likely if you are using Windows, you will need to go to the Scripts directory of the Python version you installed.
How to Upgrade pip?
I have come across upgrading my pip version a few times and this command does come in handy in many cases. From my experience, when trying to install new packages, Python prompts that pip needs to be updated to the newest version with the below command in Windows:
python -m pip install -U pip
Python pip Commands
In order, to test out some of these commands, pip must be installed and hopefully it is before moving forward in this tutorial. If you are using Windows, load the command prompt (cmd) and type pip. This will output a list of commands and the options available:
The pip search command will allow you to search through packages within the Python central package repository. As you can see from the below, this will generate a lost of packages with the term “numpy” in the description or name of the package.
pip install <package name>
The Python pip install command installs the package and dependencies into the selected Python environment. Always make sure to verify which package version you are installing and specify the version if you require a specified version on your own package or code. For instance, if you wanted to install the NumPy package, you would do so as shown below:
The pip list command will list all currently installed Python packages and the versions associated with each installed package.
The pip freeze command is a very important command when trying to build a list of all the packages you need. Instead of printing out the installed packages and version like the pip list command, the pip freeze command will output installed packages in requirements format.
pip freeze > package_requirements.txt