You may choose one of two methods to install treelite on your system:
This is probably the most convenient method. Simply type
pip3 install --user treelite
to install the treelite package. The command will locate the binary release that is compatible with your current platform. Check the installation by running
import treelite
in an interactive Python session. This method is available for only Windows, Mac OS X, and Linux. For other operating systems, see the next section.
Installation consists of two steps:
Note
List of libraries created
There will be two libraries created: the main library, for producing optimized prediction subroutines; and the runtime library, for deploying these subroutines in the wild for actual prediction tasks.
Operating System | Main library | Runtime library |
---|---|---|
Windows | treelite.dll |
treelite_runtime.dll |
Mac OS X | libtreelite.dylib |
libtreelite_runtime.dylib |
Linux / other UNIX | libtreelite.so |
libtreelite_runtime.so |
To get started, clone treelite repo from GitHub. It is important to clone the
submodules with --recursive
option.
git clone --recursive https://github.com/dmlc/treelite.git
cd treelite
The next step is to build the shared libraries.
The Python package is located at the python
subdirectory. There are several
ways to install the package:
1. Install system-wide, which requires root permission
cd python
sudo python setup.py install
You will need Python setuptools
module for this to work. It is often part of the core Python installation.
Should it be necessary, the package can be installed using pip
:
pip install -U pip setuptools
2. Install for only current user
This is useful if you do not have the administrative rights.
cd python
python setup.py develop --user
Note
Recompiling treelite
Every time the C++ portion of treelite gets re-compiled, the Python package must be re-installed for the new library to take effect.
3. Set the environment variable PYTHONPATH to locate treelite package
Only set the environment variable PYTHONPATH
to tell Python where to find
the treelite package. This is useful for developers, as any changes made
to C++ code will be immediately visible to Python side without re-running
setup.py
.
export PYTHONPATH=path/to/treelite/python
python # enter interactive session
Note
Compiling with Protocol Buffers support
If your system has Protocol Buffers (google/protobuf) library installed, treelite will be compiled with Protocol Buffers support. That is, you will able to read tree ensemble models that had been serialized using Protocol Buffers. Protocol Buffers support is strictly optional; treelite can be compiled without it. Should you decide to use Protocol Buffers, you should specify your ensemble model according to the specification src/tree.proto.
Binary releases hosted on PyPI have been compiled with Protocol Buffers support.
On Windows, you should specify the root directory containing Protobuf
compilers and libraries by setting the environment variable
CMAKE_PREFIX_PATH
as follows:
mkdir build
cd build
:: Specify location of protobuf (Protocol Buffers)
set CMAKE_PREFIX_PATH=C:\path\to\protobuf
cmake .. -G"Visual Studio 15 2017 Win64"