Python Mac Pip Install

/ Comments off

Pip is the standard package manager for Python. It enables the installation and management of third party packages that provide features and functionality not contained in the Python standard library. Newer versions of Python (Python 2 >= v2.7.9 or Python 3 >= v3.4) come prepackaged with pip by default. Pip is also included in the virtual environments created by virtualenv and pyvenv.

Using The Microsoft Store. Microsoft hosts a community release of Python 3 in the Microsoft Store. This is the recommended way to install Python on Windows because it handles updates automatically and can be uninstalled easily too. To use this method: open the Microsoft store and search for Python. Pick the newest version and install it. The main advantage of that solution is that it install pip for the python version that has been used to run get-pip.py, which means that if you use the default OS X installation of python to run get-pip.py you will install pip for the python install from the system. Install Pip with get-pip.py On MacOS. This python file get-pip.py is a script that will download and install the Pip package for the Python language. The first step is to download the get-pip.py script using the curl command ( if you want more details about this command, please read the article I wrote about this command). Execute the following.

But if your default Python is an older version of Python, pip will need to be manually installed. This tutorial steps through how to:

  • Install pip on your Windows or macOS operating system
  • Use pip to manage your environment

Prerequisites for Pip Installation

Check to see which version of Python you have installed by running the following command:

Depending on your Python installation, you should see something like the following:

If you do not have a version of Python installed, you can quickly download and install a recent version of ActiveState.

Check to see if pip is already installed by running the following on the command line:

You should see something similar to the following output:

Install Pip on Windows or Mac

To manually install pip on Windows or Mac (including Mac OS X), you will need a copy of get-pip.py. For older Python versions, you may need to use the appropriate version of the file from pypa.org. You can get a copy of the installer by downloading the file to a folder on your computer, or else just use the following curl command:

Next, run the following command to install pip:

If the file is not found, you may need to first navigate to the directory containing the get-pip.py file. For a Windows installation, you should see something similar to the following:

Installing collected packages: pip, setuptools, wheel

The script wheel.exe is installed in ‘C:Python33Scripts’ which is not on PATH.

Consider adding this directory to PATH or, if you prefer to suppress this warning, use

Pip

This command will also install setuptools and wheel if they are not already installed.

Add Pip to Windows Environment Variables

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you’re trying to run in your current directory. There are two solutions:

  • Navigate to the directory in which pip is installed every time before you run pip, or else prefix the command with the path.
  • Add the directory in which pip is installed as a PATH environment variable so you can run it from any location.

You can update the PATH environment variable on Windows by doing the following:

  1. Open up the Control Panel and navigate to System and Security > System
  2. Click on the Advanced system settings link on the left panel
  3. Click Environment Variables.
  4. Under System Variables, double-click the variable PATH.
  5. Click New, and add the directory where pip is installed, e.g. C:PythonScripts, and select OK.

Add Pip to the Mac Environment Variables

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you’re trying to run in your current directory.

The best solution is to edit your .bash_profile by doing the following:

And then add in the following commands:

Where “your path” might be something like:

Save the file and check whether the PATH has been updated by running:

Upgrade Pip

In order to keep your version of pip up to date, you can run the following on the command line:

This command will uninstall the outdated version of pip first, and then download the latest version.

Using Pip to Manage Environments

Pip is the default package manager for Python that most developers use to manage their Python global and virtual environments by installing, updating and uninstalling packages and their dependencies. By default, pip installs packages located in the Python Package Index (PyPI), but can also install from other indexes.

Unfortunately, pip does not resolve dependencies, which means it’s possible to corrupt your environment, especially when performing updates of packages in the site-packages directory. Instead, consider installing Python from ActiveState for Windows and Linux and then importing your requirements file. The ActiveState Platform will automatically resolve all packages and their dependencies to ensure against conflicts.

Pip Package Installation

Python packages installed with pip are typically bundled into ‘wheels’ prior to installation. A wheel is a zip-style archive that contains all the files necessary for a typical package installation. Wheels have a .whl extension, and provide a simpler installation than ‘non-wheel’ packages.

To install a package:

To install a specific version of a package:

Python Macos Pip Install

For example,

To install a package from a repository other than PyPI, for instance, Github:

To upgrade a package that is already installed:

To uninstall a package:

To show help for pip, including complete command usage and options:

Pipenv Package Installation

Pipenv is a tool for managing dependencies. It uses pip and virtualenv under the hood (you may need to install virtualenv if it isn’t already installed), and simplifies their usage with a single command line syntax. Like venv, pipenv automatically creates a new virtual environment for each project.

To install, upgrade or uninstall packages within pipenv, just replace the pip command with pipenv. For example, the following command installs a named package from PyPI:

You can also install packages into your Python virtual environment from locations other than PyPI. For example, the following command installs the requests package from a Github repository:

Install Python Packages the secure, modern way

The ActiveState Platform is a package management solution for Python, Perl and Tcl that automatically creates a virtual environment on all main operating systems, including Windows, Linux or macOS whenever you install a new Python project.

The ActiveState Platform provides a command line interface, the State Tool, which automatically:

  • Creates a project folder for your virtual environment
  • Builds Python from source code, downloads and installs it in the virtual environment
  • Builds all packages/dependencies from source code, downloads and installs them into the virtual environment

In this way, you don’t need to have Python or venv or virtualenv or pipenv installed before you can create a virtual environment. Anytime you need to start a new Python project or create a new Python installation, you can simply run a single command to:

Osx Python Pip Install

  • Download and install Python and the Python interpreter
  • Download and install key dependencies like setup.py and setuptools

You can watch a video to see how to install Python 3.9 into a virtual environment, or you can simply try it out for yourself:

For Windows, run the following command at a CMD prompt:

Mac Python Pip Install Pandas

For Linux run the following command:

You can then install any Python packages your project requires by running:

Or

For more information on how to use the State Tool, refer to the User Guide.

Ready to see for yourself? You can try the ActiveState Platform by signing up for a free account using your email or GitHub credentials. Or sign up for a free demo and let us show you how you can automatically build your Python environment in minutes.