Installing Core ML Tools — Guide to Core ML Tools (original) (raw)

Contents

Installing Core ML Tools#

This page describes how to install the coremltools Python package on macOS (10.13+) and Linux.

Supported Python and MacOS Versions

The current version of coremltools (version 8.0) includes wheels for Python 3.7, 3.8, 3.9, 3.10, 3.11, and 3.12. The last stable release of coremltools to support Python 2 is version 4.0.

The supported MacOS versions are as follows:

Prerequisites#

Before installing coremltools, you need Python and the pip installer.

The coremltools package supports Python 3. We recommend that you install Python 3.6 or newer. Use a Python package manager such as Conda or venv to install the newest version of Python and other dependencies. Conda is recommended because it is the most reliable way to install all required dependencies.

Install or Build Core ML Tools#

To install Core ML Tools, use one of the following methods:

To install third-party frameworks, libraries, or other software, see Install Third-party Packages.

Set Up Conda#

Follow these steps:

  1. Use the appropriate Miniconda installer for your operating system.
  2. Create a Conda environment for coremltools using the following command:

conda create --name coremltools-env

  1. Activate your virtual environment using the following command:

conda activate coremltools-env

  1. Install pip for this environment using the following command:
  2. Follow the instructions in Install Core ML Tools.

Set Up a New Virtual Environment#

Follow these steps:

  1. Install pip using the following command:

python -m pip install --user --upgrade pip

  1. Create a virtual environment using the following command:

python -m venv coremltools-venv

  1. Activate the virtual environment:

source coremltools-venv/bin/activate

  1. Follow the instructions in Install Core ML Tools.

Install Core ML Tools#

Use the following command to install or upgrade to version 7.1 of Core ML Tools:

pip install -U coremltools

Install Third-party Packages#

Install the third-party source packages for your conversions (such as TensorFlow and PyTorch) using the package guides provided for them. The coremltools package does not include the third-party source packages.

Install From Source#

The continuous integration (CI) system linked to the coremltools repo builds a Python wheel from the master branch whenever a commit is merged. To get the latest updates to the code base, you can get this wheel from the CI job and install it.

To access the wheel for a particular coremltools release, follow these steps:

  1. Go to the coremltools repository on GitHub, scroll down to the README.md heading, and click the build passing button. The Branches tab appears:
    Branches tab
    Branches passed
  2. Click the passed button to show the Pipeline tab:
    Pipeline tab
  3. Click a wheel in the Build column. For example, in the previous figure, the build_wheel_macos_py38 wheel is highlighted for clicking. After clicking a wheel, the raw job log appears, with the Download and Browse buttons in the right column:
    Download and Browse
  4. Click the Download button to download the dist folder with the wheel files.
  5. Install a wheel file using pip. For example, use the following command to install the coremltools-4.0-cp38-none-macosx_10_12_intel.whl wheel file for the 4.0 version of Core ML Tools:

pip install coremltools-4.0-cp38-none-macosx_10_12_intel.whl

Build From Source#

To build Core ML Tools and its dependent libraries from source, you need to install CMake to configure the project.

To perform the build, fork and clone the coremltools repository and run the build.sh script:

The script creates a new build folder with the coremltools distribution, and a dist folder with Python wheel files.

For more information about building Core ML Tools, see Building From Source.

Upgrade Core ML Tools#

For either Conda or virtual environments, see Install Core ML Tools for the command to upgrade Core ML Tools.