# 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.0, 1.0))
b = tf.Variable(tf.zeros())
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
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:

## 11 thoughts on “Install Tensorflow on Ubuntu with Virtualenv”

1. marrman says:

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. admin says:

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

2. Kamal says:

The root is unreadable.What should I do?

1. admin says:

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

3. Dileep Kumar says:

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??

4. vijay says:

hey niandrei.
first of all thanks a lot for such a lovely installation guide.

all the best for your future ventures .

1. admin says:

Thank you very much. Have a great day!

5. MartinUnary says:

Hi All im newbie here. Good post! Thx! Thx!

6. joseph pareti says:

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