Save the date! Google I/O returns May 18-20 Register now

Install TensorFlow for Go

TensorFlow provides a Go API— particularly useful for loading models created with Python and running them within a Go application.

Supported Platforms

TensorFlow for Go is supported on the following systems:

  • Linux, 64-bit, x86
  • macOS, Version 10.12.6 (Sierra) or higher


TensorFlow C library

Install the TensorFlow C library which is required for the TensorFlow Go package.


Download and install the TensorFlow Go package and its dependencies:

go get

And validate your installation:

go test


Example program

With the TensorFlow Go package installed, create an example program with the following source code (hello_tf.go):

package main

import (
    tf ""

func main() {
    // Construct a graph with an operation that produces a string constant.
    s := op.NewScope()
    c := op.Const(s, "Hello from TensorFlow version " + tf.Version())
    graph, err := s.Finalize()
    if err != nil {

    // Execute the graph in a session.
    sess, err := tf.NewSession(graph, nil)
    if err != nil {
    output, err := sess.Run(nil, []tf.Output{c}, nil)
    if err != nil {


Run the example program:

go run hello_tf.go

The command outputs: Hello from TensorFlow version number

The program may generate the following warning messages, which you can ignore:

W tensorflow/core/platform/] The TensorFlow library
wasn't compiled to use *Type* instructions, but these are available on your
machine and could speed up CPU computations.

Build from source

TensorFlow is open source. Read the instructions to build TensorFlow for Go from source code.