# Install Neural Structured Learning

There are several ways to set up your environment to use Neural Structured
Learning (NSL) in TensorFlow:

- The easiest way to learn and use NSL requires no installation: run the NSL tutorials directly in your browser using [Google Colaboratory](https://colab.research.google.com/notebooks/welcome.ipynb).
- To use NSL on a local machine, install the [NSL package](https://www.tensorflow.org/neural_structured_learning/install#install_neural_structured_learning_using_pip) with Python's `pip` package manager.
- If you have a unique machine configuration, [build NSL](https://www.tensorflow.org/neural_structured_learning/install#build_the_neural_structured_learning_pip_package) from source.

> [!NOTE]
> **Note:** NSL requires a TensorFlow version of 1.15 or higher. NSL also supports TensorFlow 2.x with the exception of v2.1, which contains a bug that is incompatible with NSL.

## Install Neural Structured Learning using pip

#### 1. Install the Python development environment.

On Ubuntu:

    sudo apt update
    sudo apt install python3-dev python3-pip  # Python 3
    sudo pip3 install --upgrade virtualenv  # system-wide install

On macOS:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
    brew update
    brew install python  # Python 3
    sudo pip3 install --upgrade virtualenv  # system-wide install

#### 2. Create a virtual environment.

    virtualenv --python python3 "./venv"
    source "./venv/bin/activate"
    pip install --upgrade pip

> [!NOTE]
> **Note:** To exit the virtual environment, run `deactivate`.

#### 3. Install TensorFlow

CPU support:

    pip install 'tensorflow>=1.15.0'

GPU support:

    pip install 'tensorflow-gpu>=1.15.0'

#### 4. Install the Neural Structured Learning `pip` package.

    pip install --upgrade neural_structured_learning

#### 5. (Optional) Test Neural Structured Learning.

    python -c "import neural_structured_learning as nsl"

> [!TIP]
> **Success:** Neural Structured Learning is now installed.

## Build the Neural Structured Learning pip package

#### 1. Install the Python development environment.

On Ubuntu:

    sudo apt update
    sudo apt install python3-dev python3-pip  # Python 3
    sudo pip3 install --upgrade virtualenv  # system-wide install

On macOS:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
    brew update
    brew install python  # Python 3
    sudo pip3 install --upgrade virtualenv  # system-wide install

#### 2. Install Bazel.

[Install Bazel](https://docs.bazel.build/versions/master/install.html), the
build tool used to compile Neural Structured Learning.

#### 3. Clone the Neural Structured Learning repository.

    git clone https://github.com/tensorflow/neural-structured-learning.git

#### 4. Create a virtual environment.

    virtualenv --python python3 "./venv"
    source "./venv/bin/activate"
    pip install --upgrade pip

> [!NOTE]
> **Note:** To exit the virtual environment, run `deactivate`.

#### 5. Install Tensorflow

Note that NSL requires a TensorFlow version of 1.15 or higher. NSL also supports
TensorFlow 2.0.

CPU support:

    pip install 'tensorflow>=1.15.0'

GPU support:

    pip install 'tensorflow-gpu>=1.15.0'

#### 6. Install Neural Structured Learning dependencies.

    cd neural-structured-learning
    pip install --requirement neural_structured_learning/requirements.txt

#### 7. (Optional) Unit Test Neural Structured Learning.

    bazel test //neural_structured_learning/...

#### 8. Build the pip package.

    python setup.py bdist_wheel --universal --dist-dir="./wheel"

#### 9. Install the pip package.

    pip install --upgrade ./wheel/neural_structured_learning*.whl

#### 10. Test Neural Structured Learning.

    python -c "import neural_structured_learning as nsl"

> [!TIP]
> **Success:** The Neural Structured Learning package is built.