This page describes how to build Core ML Tools (coremltools) from the source repository.
To build coremltools from source, you need the following:
- CMake
- Miniconda (or Anaconda)
- Zsh shell (the default shell for macOS 10.16+) installed in /usr/bin
- A C++17 compatible compiler (if using GCC, need GCC 9.0 or later)
Follow these steps:
-
Fork and clone the GitHub coremltools repository.
-
Run the build.sh script to build
coremltools
.- By default this script uses Python 3.7, but you can include
--python=3.8
(or3.9
,3.10
,3.11
) as a argument to change the Python version. - The script creates a new
build
folder with the coremltools distribution, and adist
folder with Python wheel files.
- By default this script uses Python 3.7, but you can include
-
Run the test.sh script to test the build.
Under the hood: If an Anaconda or Miniconda environment doesn't already exist or is not up-to-date, the build.sh
script automatically runs the env_create.sh
script to create the environment. It then uses env_activate.sh
to activate the environment and set up the appropriate version of Python. The new environment is located at <repo root>/coremltoos/envs
and is named after the py
parameter. For example, a development environment with py 3.7 is named coremltools-dev-py37
.
The following build targets help you configure the development environment. If you need to add packages, edit the reqs/pip
files, and the auto-environment script installs them automatically.
build
| Build coremltools in debug mode (include symbols).docs
| Build documentation.clean
| Clean build dir.clean_envs
| Delete allenvs
created by the scripts.lint
| Linter.proto
| Build coremltools and rebuild MLModel protobuf sources.release
| Set up the package for release, but don't upload to pypi. Include all wheels frombuild/dist
in the built package.style
| Style checking.test
| Run all tests. PassTEST_PACKAGES="..."
to set which packages to test.test_fast
| Run all fast tests.test_slow
| Run all non-fast tests.wheel
| Build wheels in release mode.
The script uses Python 3.7, but you can include --python=3.8
(or 3.9
, 3.10
, 3.11
) as a argument to change the Python version.
For more information, see the following:
- Core ML Tools README file for this repository
- Release Notes for the current release and previous releases
- Guides and examples with installation and troubleshooting help
- API Reference
- Core ML Specification
- Contribution Guidelines for reporting issues and making pull requests