# Install TensorFlow Federated

<br />

There are a few ways to set up your environment to use TensorFlow Federated
(TFF):

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

## Install TensorFlow Federated using `pip`

### 1. Install the Python development environment.

    sudo apt update
    sudo apt install python3-dev python3-pip  # Python 3

### 2. Create a virtual environment.

    python3 -m venv "venv"
    source "venv/bin/activate"
    pip install --upgrade "pip"

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

### 3. Install the released TensorFlow Federated Python package.

    pip install --upgrade tensorflow-federated

### 4. Test Tensorflow Federated.

    python -c "import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())"

> [!TIP]
> **Success:** The latest TensorFlow Federated Python package is now installed.

## Build the TensorFlow Federated Python package from source

Building a TensorFlow Federated Python package from source is helpful when you
want to:

- Make changes to TensorFlow Federated and test those changes in a component that uses TensorFlow Federated before those changes are submitted or released.
- Use changes that have been submitted to TensorFlow Federated but have not been released.

### 1. Install the Python development environment.

    sudo apt update
    sudo apt install python3-dev python3-pip  # Python 3

### 2. Install Bazel.

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

### 3. Clone the Tensorflow Federated repository.

    git clone https://github.com/google-parfait/tensorflow-federated.git
    cd "tensorflow-federated"

### 4. Create a virtual environment.

    python3 -m venv "venv"
    source "venv/bin/activate"
    pip install --upgrade "pip"
    pip install numpy

### 5. Build the TensorFlow Federated Python package.

    mkdir "/tmp/tensorflow_federated"
    bazel run //tools/python_package:build_python_package -- \
        --output_dir="/tmp/tensorflow_federated"

### 6. Exit the virtual environment

    deactivate

### 7. Create a new project.

    mkdir "/tmp/project"
    cd "/tmp/project"

### 8. Create a new virtual environment.

    python3 -m venv "venv"
    source "venv/bin/activate"
    pip install --upgrade "pip"

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

### 9. Install the TensorFlow Federated Python package.

    pip install --upgrade "/tmp/tensorflow_federated/"*".whl"

### 10. Test Tensorflow Federated.

    python -c "import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())"

> [!TIP]
> **Success:** A TensorFlow Federated Python package is now built from source and installed.