Installation
This page describes how to install the coremltools Python package on macOS (10.13+) and Linux.
Core ML Tools 5.2 available now!
If you have already set up an environment, see Install coremltools. For complete instructions see Install or build coremltools.
Supported Python versions
Support for Python 2 has been deprecated since coremltools 4.1. The current version of coremltools includes wheels for Python 3.5, 3.6, 3.7, 3.8 and 3.9.
The most recent stable release of coremltools to support Python 2 is version 4.0.
Supported MacOS versions
- coremltools 4.1 supports macOS 10.13 and newer.
- coremltools 5 supports macOS 10.15 and newer.
Prerequisites
For beginners
If you are using macOS, you should already be familiar with the Mac Terminal app command line to perform tasks such as installations and updates. If you are using Linux, you should already be familiar with basic Shell commands in Linux.
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 coremltools
To install coremltools, use one of the following methods:
- The Conda package installer: Python is installed automatically. You can install pip after setting up the Conda environment. Skip to Set up Conda.
- A virtual environment: Install pip, and then use venv, which also installs Python. Skip to Set up a new virtual environment.
- Install Python wheel: To download and install the most recent (or any available) Python wheel (
.whlfile) for coremltools, see Install from source. - Build from source: To build the most recent (or any available) version of coremltools, see Build from source.
To install third-party frameworks, libraries, or other software, see Install third-party packages.
Set up Conda
Follow these steps:
-
Use the appropriate Miniconda installer for your operating system.
-
Create a Conda environment for coremltools using the following command:
conda create --name coremltools-env
- Activate your virtual environment using the following command:
conda activate coremltools-env
- Install pip for this environment using the following command:
conda install pip
Set up a new virtual environment
Follow these steps:
- Install pip using the following command:
python -m pip install --user --upgrade pip
- Create a virtual environment using the following command:
python -m venv coremltools-venv
- Activate the virtual environment:
source coremltools-venv/bin/activate
Install coremltools
Use the following command to install or upgrade to the newest version of coremltools:
pip install 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:
- Go to the Apple coremltools repository on GitHub, scroll down to the README.md heading, and click the build passing button. The Branches tab appears.
- Click the passed button to show the Pipeline tab.
- Click a wheel in the Build column. For example, in the previous figure, the
build_wheel_macos_py38wheel is highlighted for clicking. After clicking a wheel, the raw job log appears, with the Download and Browse buttons in the right column.
-
Click the Download button to download the
distfolder with the wheel files. -
Install a wheel file using pip. For example, use this command to install the
coremltools-4.0-cp38-none-macosx_10_12_intel.whlwheel file for the 4.0 version of coremltools:
pip install coremltools-4.0-cp38-none-macosx_10_12_intel.whl
Build from source
To build coremltools and its dependent libraries from source, you need to install CMake to configure the project.
To perform the build, fork and clone the GitHub coremltools repository and run the build.sh script:
zsh -i scripts/build.sh
The script creates a new build folder with the coremltools distribution, and a dist folder with Python wheel files.
For more information about building coremltools, see Building From Source.
Upgrade coremltools
For either Conda or virtual environments, see Install coremltools for the command to upgrade coremltools.
Updated almost 4 years ago
