Install Tensorflow on Ubuntu with Virtualenv

Tensorflow on Ubuntu 14.4 (64).

Here is a video version of this tutorial:

And here is the terminal commands and code used:

  1. sudo su
  2. sudo apt-get install python-pip python-dev python-virtualenv
  3. virtualenv --system-site-packages ~/tensorflow
  4. source ~/tensorflow/bin/activate
  5. pip install --upgrade

Find the tenserFlow location:

  1. python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'

The test project:

import tensorflow as tf
import numpy as np

# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but Tensorflow will
# figure that out for us.)
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# Before starting, initialize the variables.  We will 'run' this first.
init = tf.initialize_all_variables()

# Launch the graph.
sess = tf.Session()

# Fit the line.
for step in xrange(201):
    if step % 20 == 0:

# Learns best fit is W: [0.1], b: [0.3]

Start the test project:

  1. python -m tensorflow.test

[xyz-ihs snippet=”Yllix-Ads”]

Source pages:

Share this info with your audience:
Was this helpful?

11 thoughts on “Install Tensorflow on Ubuntu with Virtualenv

  1. I believe I ran everything prior to the sample program just fine. But on the same program I got the error message of: bash: syntax error near unexpected token `(‘

  2. Hi ,
    I got this Error “tensorflow-0.7.1-cp27-none-linux_x86_64.whl is not a supported wheel on this platform”. How can I solve this??

  3. why sudo apt-get install python-pip python-dev python-virtualenv ?

    do you assume python is not yet there? What happens if it is?
    I understood the appeal of virtualenv is to avoid screwing up your host setup, but the above command will change the host environment

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Buy me a coffee