Brew vs. Pip: Which Package Installer Should You Use?

[article]
Summary:
A command-line package installer is a handy tool that installs your desired software package without a fancy UI, yet it often proves to be more effective than some tools integrated into expensive IDEs. Brew and Pip are two of the more popular options for package installers when using the script language Python. But what’s the difference between them, and which makes more sense for your use? Here’s an introduction to Brew and Pip for testers.

Python is the most popular testing automation script language nowadays. If you want to work with Python, you need a command-line package installer to install and manage additional libraries and dependencies that are not distributed as part of the standard libraries.

This handy tool downloads and installs your desired software package without a fancy UI, yet it often proves to be more effective than some tools integrated into expensive IDEs.

Brew and Pip are two of the more popular options for package installers for Python. But what’s the difference between them, and which makes more sense for your use? Here’s an introduction to Brew and Pip for testers.

What Is Brew?

Brew is an open source, community-maintained software for installing general software packages on OS X. (I was introduced to Brew when Pip wasn’t working successfully on my Mac, especially with the High Sierra OS version. Brew installed all my necessary modules right away.) You can find its repository written in Ruby on GitHub.

The packages it installs include all kinds of Python stuff, but they are not limited to Python. And to make its usage fun, the creators named all kinds of terms connected to beer, like “cask,” “bottles,” and “tap.”

Installing Brew is pretty easy: You just have to run a specific curl command in the terminal of your Mac. The specific command can be found at the Brew homepage. This installation will set up files into your /usr/local folder, or wherever you specify it. Actually, this will be a GitHub repository, core files, and formulae─the latter means Ruby files that describe the software they install and contain instructions to install and test it.

After Brew is installed, you specify what package is needed as a parameter, and the software downloads it into your ~/Library/Caches/Homebrew folder using curl. It checks the validity of the package with a checksum (you can read about it in detail here), so it can be considered pretty much safe. Then, Brew installs the package into the appropriate bin folder specified in the formulae. Finally, it symlinks these files into /usr/local, which means a symbolic link or a kind of shortcut—a file pointing to another file.

Brew requires manual update from time to time. You can upgrade everything (Brew itself and other packages) with the brew upgrade command. You can also read about updates and future plans in their Twitter page.

If you’re interested in contributing to Brew, you can create a pull request on the GitHub repository. After you make some serious contributions—not just changing some formulae but developing new features of fixing bugs—you may get an invitation to become a maintainer. The detailed process can be found here.

What Is Pip?

Pip is also a packager that is open source and available on GitHub. It's written in Python, and you can use it on all kinds of operating systems but for installing Python packages only. 

There’s good news about installation: Pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded frompython.org. If you are using previous versions, check the detailed installation guide here.

After Pip is installed, you have to specify what package you need. The software looks for it in the Python Package Index (PyPI), a repository where the very active Python community hosts its growing set of packages. Pip searches for the latest version and calculates the dependencies of that particular package, then installs all of them to insure the new package will work. You can also search for more enhanced packages with the pip search [package] command, but you can use the slightly more user-friendly PyPI website for that.

After a few months, your Pip version can become so obsolete that it will warn you about an upgrade needed. You can upgrade it by just copying and pasting the command suggested by the warning: python -m pip install --upgrade pip.

Contributing to the project is not so organized, but you can do it with a pull request. The detailed process can be found here.

Comparing the Tools

If you would like to install a certain Python package like requests, you can use the following commands to do so once you have your package installer of choice:

brew install requests
or
pip install requests

At the end of the day, you should get your desired package using any of these methods ─ but the exact installation flow depends on your OS and the tools detailed above.

Now, with the process described here, you can install Python packages necessary for your testing, like pytest, requests, or selenium.

In short, here’s a comparison of the two tools:

Infographic showing Brew vs. Pip at a glance

About the author

StickyMinds is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.