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 https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

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()
sess.run(init)

# Fit the line.
for step in xrange(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(W), sess.run(b))

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

Start the test project:

  1. python -m tensorflow.test

 

Source pages:

  1. https://www.tensorflow.org/versions/r0.7/get_started/os_setup.html#test-the-tensorflow-installation
  2. https://www.tensorflow.org/versions/r0.7/get_started/os_setup.html#virtualenv-installation

9 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 `(‘

    1. Sorry for the late response. Have you managed to solve this? Do you get a file reference/line position where this error is happening?

    1. What do you mean by “unreadable”? Can you tell me the error you get, and on which step?

  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. hey niandrei.
    first of all thanks a lot for such a lovely installation guide.

    all the best for your future ventures .

Leave a Reply

Your email address will not be published. Required fields are marked *