Stay organized with collections
Save and categorize content based on your preferences.
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.
To use TensorFlow Federated on a local machine,
install the TFF package with
Python's pip package manager.
3. Install the released TensorFlow Federated Python package.
pipinstall--upgradetensorflow-federated
4. Test Tensorflow Federated.
python-c"import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())"
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-01-30 UTC."],[],[],null,["# Install TensorFlow Federated\n\n\u003cbr /\u003e\n\nThere are a few ways to set up your environment to use TensorFlow Federated\n(TFF):\n\n- 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).\n- To use TensorFlow Federated on a local machine, [install the TFF package](#install_tensorflow_federated_using_pip) with Python's `pip` package manager.\n- If you have a unique machine configuration, [build the TFF package from source](#build_the_tensorflow_federated_python_package_from_source) .\n\nInstall TensorFlow Federated using `pip`\n----------------------------------------\n\n### 1. Install the Python development environment.\n\n sudo apt update\n sudo apt install python3-dev python3-pip # Python 3\n\n### 2. Create a virtual environment.\n\n python3 -m venv \"venv\"\n source \"venv/bin/activate\"\n pip install --upgrade \"pip\"\n\n| **Note:** To exit the virtual environment, run `deactivate`.\n\n### 3. Install the released TensorFlow Federated Python package.\n\n pip install --upgrade tensorflow-federated\n\n### 4. Test Tensorflow Federated.\n\n python -c \"import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())\"\n\n| **Success:** The latest TensorFlow Federated Python package is now installed.\n\nBuild the TensorFlow Federated Python package from source\n---------------------------------------------------------\n\nBuilding a TensorFlow Federated Python package from source is helpful when you\nwant to:\n\n- Make changes to TensorFlow Federated and test those changes in a component that uses TensorFlow Federated before those changes are submitted or released.\n- Use changes that have been submitted to TensorFlow Federated but have not been released.\n\n### 1. Install the Python development environment.\n\n sudo apt update\n sudo apt install python3-dev python3-pip # Python 3\n\n### 2. Install Bazel.\n\n[Install Bazel](https://docs.bazel.build/versions/master/install.html), the\nbuild tool used to compile Tensorflow Federated.\n\n### 3. Clone the Tensorflow Federated repository.\n\n git clone https://github.com/google-parfait/tensorflow-federated.git\n cd \"tensorflow-federated\"\n\n### 4. Create a virtual environment.\n\n python3 -m venv \"venv\"\n source \"venv/bin/activate\"\n pip install --upgrade \"pip\"\n pip install numpy\n\n### 5. Build the TensorFlow Federated Python package.\n\n mkdir \"/tmp/tensorflow_federated\"\n bazel run //tools/python_package:build_python_package -- \\\n --output_dir=\"/tmp/tensorflow_federated\"\n\n### 6. Exit the virtual environment\n\n deactivate\n\n### 7. Create a new project.\n\n mkdir \"/tmp/project\"\n cd \"/tmp/project\"\n\n### 8. Create a new virtual environment.\n\n python3 -m venv \"venv\"\n source \"venv/bin/activate\"\n pip install --upgrade \"pip\"\n\n| **Note:** To exit the virtual environment, run `deactivate`.\n\n### 9. Install the TensorFlow Federated Python package.\n\n pip install --upgrade \"/tmp/tensorflow_federated/\"*\".whl\"\n\n### 10. Test Tensorflow Federated.\n\n python -c \"import tensorflow_federated as tff; print(tff.tensorflow_computation(lambda: 'Hello World')())\"\n\n| **Success:** A TensorFlow Federated Python package is now built from source and installed."]]