In Python, using Python packages published by other developers in your own project is one thing that will make your life easier. The Python Package Index, or PyPI, is a huge repository of code you can use. Learn how to get you started with PyPI and its installer program, PIP (Package Installer for Python).

How to Install PIP on macOS

PIP is the default package installer and was recently added to to the core distribution of Python. This means to install PIP we need to install Python.

These instructions should work on any macOS version supported by the current Python installer, which includes v10.6+ (Snow Leopard) for the 32-bit installer, and v10.9 (Mavericks) for the 64-bit-only version of the current installer.

While Python 2 used to come pre-installed in macOS, you should use the newer version, Python 3. The only reason to continue using v2.7 is to support older, existing applications. Luckily, if you’re just getting started, you don’t have any of these.

Python installation is a standard .PKG-based affair. To get it up and running, take the following steps:

  • First, head to the Python website and grab the latest release. Unless you’re on an older machine and have to use a previous version of macOS for some reason, download the 64-bit installer file.
  • This is the standard macOS .PKG format, so you can just click the installer file to kick things off.
  • The first screen will provide some info on the install, click Continue to move along.
  • Click Continue on the following page as well, which lets you know the project will stop providing support for 32-bit installers from v3.8 onward.
  • The next screen asks you to accept the license for Python. Click Continue, then click Agree.
  • You’ll need to select a destination for the install on the following screen. You can click Install to place it on your main drive, or click Customize if you have somewhere else in mind. You’ll also need to enter your password to continue.
  • Now the installer will start copying the files.
  • Once the installation is finished, the app’s folder will open in Finder.

Examining the Python Install on macOS

The installation contains a few items, as follows:

First, head to the Python website and grab the latest release. Unless you’re on an older machine and have to use a previous version of macOS for some reason, download the 64-bit installer file.

This is the standard macOS .PKG format, so you can just click the installer file to kick things off.

The first screen will provide some info on the install, click Continue to move along.

Click Continue on the following page as well, which lets you know the project will stop providing support for 32-bit installers from v3.8 onward.

The next screen asks you to accept the license for Python. Click Continue, then click Agree.

You’ll need to select a destination for the install on the following screen. You can click Install to place it on your main drive, or click Customize if you have somewhere else in mind. You’ll also need to enter your password to continue.

Now the installer will start copying the files.

Once the installation is finished, the app’s folder will open in Finder.

  • Two .RTF files: Once contains the License; the other the ReadMe file.Two .COMMAND files: These are there to help perform some configuration. The Install Certificates.command file will set up some SSL certificates, and the Update Shell Profile.command file will help if you have trouble using Python 3, and find that you’re always being directed to Python 2.IDLE app: An integrated development environment specifically for Python.Python Launcher: Helps you to configure some settings related to launching Python scripts.

How to Confirm Python Is Working on macOS

Before you can use Python, it’s best to confirm your Python installation is working correctly.

  • Try the following command in Terminal:
  • python –versionPython 3.7.4
  • If you want to further confirm things, try running a simple Python script. Enter (or paste) the following code into an empty text file and naming it “hello-world.py”:
  • print (“Hello World!”)
  • Now, at the command prompt, run the following:
  • python \path\to\hello-world.pyHello World!

How to Use Python’s PIP on macOS

We know now Python is working, and we can move on to using PIP.

Try the following command in Terminal:

python –versionPython 3.7.4

If you want to further confirm things, try running a simple Python script. Enter (or paste) the following code into an empty text file and naming it “hello-world.py”:

print (“Hello World!”)

Now, at the command prompt, run the following:

python \path\to\hello-world.pyHello World!

Fortunately, there’s nothing to do here: PIP comes installed out-of-the-box on newer versions of Python. That said, you should familiarize yourself with it.

  • Using the following command in Terminal will give you an overview of what PIP’s all about:
  • pip –help
  • The first thing you’ll probably want to do is look for a package you can use, and pip search is what you need for that. It will search the Python Package Index (PyPI) for your search term.
  • Suppose we want to create our Python application to save passwords. macOS already has a great mechanism for this: Keychain. The following command will show a list of all the packages in PyPI with the keyword “keychain”:
  • pip search keychain
  • In the results, there’s a package called macos-keychain, which is exactly what we’re looking for. So, instead of coding things like password entries, encryption, and hooking into system events, we can just download this and integrate it to our needs. You can install a package with the following command:
  • pip install macos-keychain
  • Unfortunately, updating all installed packages isn’t as easy as updating Linux distributions. You need to do so for each package when you see it’s out of date. Use the following command:
  • pip install macos-keychain –upgrade
  • Finally, removing a package is as easy as:
  • pip uninstall macos-keychain

Using the following command in Terminal will give you an overview of what PIP’s all about:

pip –help

The first thing you’ll probably want to do is look for a package you can use, and pip search is what you need for that. It will search the Python Package Index (PyPI) for your search term.

Suppose we want to create our Python application to save passwords. macOS already has a great mechanism for this: Keychain. The following command will show a list of all the packages in PyPI with the keyword “keychain”:

pip search keychain

In the results, there’s a package called macos-keychain, which is exactly what we’re looking for. So, instead of coding things like password entries, encryption, and hooking into system events, we can just download this and integrate it to our needs. You can install a package with the following command:

pip install macos-keychain

Unfortunately, updating all installed packages isn’t as easy as updating Linux distributions. You need to do so for each package when you see it’s out of date. Use the following command:

pip install macos-keychain –upgrade

Finally, removing a package is as easy as:

pip uninstall macos-keychain

Get the Latest Tech News Delivered Every Day