---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.3
alternate:
  - https://catboost.ai/docs/en/installation/python-installation-method-build-from-source-linux-macos-using-ya-make.md
---
> **Documentation Index:** Fetch the complete configuration index at https://catboost.ai/docs/en/llms.txt

# Build Python package from source on Linux and macOS using Ya Make


{% note info %}

<!-- source: en/_includes/work_src/reusage-installation/ya-make-to-cmake-switch.md -->
CatBoost uses [CMake](https://cmake.org/)-based build process since [this commit](https://github.com/catboost/catboost/commit/c5c642ca0b8e093336d0229ac4b14c78db3915bb). Previously `Ya Make` (Yandex's build system) had been used.
<!-- endsource: en/_includes/work_src/reusage-installation/ya-make-to-cmake-switch.md -->

This page describes building using Ya Make. For building using CMake see [documentation here](https://catboost.ai/docs/en/installation/python-installation-method-build-from-source.md).

{% endnote %}

## Dependencies and requirements {#dependencies-and-particularities}

1. [Setup environment for ya make build](https://catboost.ai/docs/en/installation/build-environment-setup-for-ya-make.md)

2. <!-- source: en/_includes/work_src/reusage/packages-for-installation.md -->
   The following packages are required for installation:
   <!-- endsource: en/_includes/work_src/reusage/packages-for-installation.md -->


- `python3`
- `python3-dev`
- `numpy`
- `pandas`

<!-- source: en/_includes/work_src/reusage-code-examples/nvidia-driver-reqs.md -->
Training or inference on CUDA-enabled GPUs requires NVIDIA Driver of version 450.80.02 or higher.
<!-- endsource: en/_includes/work_src/reusage-code-examples/nvidia-driver-reqs.md -->


## Building steps  {#building-steps}

To build the Python package from source on Linux and macOS:

1. Clone the repository:

    ```no-highlight
    git clone https://github.com/catboost/catboost.git
    ```

1. Open the `catboost/catboost/python-package/catboost` directory from the local copy of the CatBoost repository.

1. <!-- source: en/_includes/work_src/reusage-code-examples/compile-the-library.md -->
   Compile the packages using one of the following methods:
   - Use one of the Python versions provided by the `ya make` utility:

       ```bash
       ../../../ya make -r -DUSE_ARCADIA_PYTHON=no -DUSE_SYSTEM_PYTHON=<Python version> [optional parameters]
       ```

   - Use one of the Python versions installed on the machine:

       ```python
       ../../../ya make -r -DUSE_ARCADIA_PYTHON=no -DOS_SDK=local -DPYTHON_CONFIG=<path to the required python-config> [optional parameters]
       ```

   <table>
     <tr>
       <th>Parameter</th>
       <th>Description</th>
     </tr>
     <tr>
       <td colspan="2"><b>Parameters that define the Python version to use for compiling. Only one of the following blocks of options can be used at a time</b></td>
     </tr>
     <tr>
       <td colspan="2">Use one of the Python versions provided by the <code>ya make</code> utility</td>
     </tr>
     <tr>
        <td><code>-DUSE_SYSTEM_PYTHON</code></td><td>The version of Python to use for compiling the package on machines without installed Python.

   The following Python versions are supported and can be defined as values for this parameter:
   - 2.7
   - 3.4
   - 3.5
   - 3.6</td>
     </tr>
     <tr>
       <td colspan="2">Use one of the Python versions installed on the machine</td>
     </tr>
     <tr>
        <td><code>-DPYTHON_CONFIG</code></td><td>Defines the path to the configuration of an installed Python version to use for compiling the package.

   Value examples:
   - <code>python2-config</code> for Python 2
   - <code>python3-config</code> for Python 3
   - <code>/usr/bin/python2.7-config</code>

   <note type="attention">

   - The configuration must be explicitly named <code>python3-config</code> to successfully build the package for Python 3.
   - Manually redefine the following variables when encountering problems with the Python configuration:
       - <code>-DPYTHON_INCLUDE</code>
       - <code>-DPYTHON_LIBRARIES</code>
       - <code>-DPYTHON_LDFLAGS</code>
       - <code>-DPYTHON_FLAGS</code>
       - <code>-DPYTHON_BIN</code>

   </note></td>
     </tr>
     <tr>
       <td colspan="2"><b>Optional parameters</b></td>
     </tr>
     <tr>
        <td><code>-DCUDA_ROOT</code></td><td>The path to CUDA. This parameter is required to support training on GPU.</td>
     </tr>
     <tr>
        <td><code>-DHAVE_CUDA=no</code></td><td>Disable CUDA support. This speeds up compilation.

   By default, the package is built with CUDA support if CUDA Toolkit is installed.</td>
     </tr>
     <tr>
        <td><code>-o</code></td><td>The directory to output the compiled package to. By default, the current directory is used.</td>
     </tr>
   </table>
   <!-- endsource: en/_includes/work_src/reusage-code-examples/compile-the-library.md -->

    <!-- source: en/_includes/work_src/reusage-code-examples/installation-example.md -->
    For example, the following command builds the package for Python 3 with training on GPU support:
    ```no-highlight
    ../../../ya make -r -DUSE_ARCADIA_PYTHON=no -DOS_SDK=local -DPYTHON_CONFIG=python3-config -DCUDA_ROOT=/usr/local/cuda
    ```
    <!-- endsource: en/_includes/work_src/reusage-code-examples/installation-example.md -->

    {% note info %}

    The required version of Xcode for building on macOS is specified on the NVIDIA site when downloading the CUDA toolkit.

    {% endnote %}

1. Add the current directory to `PYTHONPATH`:
    ```
    cd ../; export PYTHONPATH=$PYTHONPATH:$(pwd)
    ```

## Troubleshooting {#troubleshooting}

Error type | Message format | Troubleshooting tips
---------- | -------------- | --------------------
`AttributeError` | ```type object '_catboost.<something>' has no attribute 'reduce_cython'```<br/><b>Example:</b><br/>```AttributeError: type object '_catboost._FloatArrayWrapper' has no attribute 'reduce_cython' ```<br/>```AttributeError: type object '_catboost.Py_ITypedSequencePtr' has no attribute 'reduce_cython' ```<br/><br/>| Install or update the following packages:<br/>- `numpy`<br/>- `pandas`
