Skip to content

Instantly share code, notes, and snippets.

@hideojoho
Last active June 11, 2018 07:19
Show Gist options
  • Save hideojoho/cfbcda17d40f440e4fd301c0e697fca7 to your computer and use it in GitHub Desktop.
Save hideojoho/cfbcda17d40f440e4fd301c0e697fca7 to your computer and use it in GitHub Desktop.
How to set up Tensorflow GPU for a new user on Ubuntu

How to set up Tensorflow GPU for a new user on Ubuntu

Install pyenv

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
exec $SHELL -l

Install latest Miniconda-3

pyenv install miniconda3-latest
pyenv rehash
pyenv global miniconda3-latest

(Option) Install libraries

conda install -y numpy matplotlib sympy pandas

Create a virtual environment of Python 3

  • We assume that we use a folder called tensorflow-gpu
mkdir tensorflow-gpu
virtualenv --system-site-packages tensorflow-gpu

Activate the virtual environment

source tensorflow-gpu/bin/activate
(tensorflow-gpu)$ pip install --upgrade tensorflow-gpu

Test the installation

(tensorflow-gpu)$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))

If you see the following message, your installation went well.

Hello, TensorFlow!

Deactivate the environment

(tensorflow-gpu)$ deactivate

Basic usage

  1. Activate the virtual environment (tensorflow-gpu)
  2. Do your stuff
  3. Deactivate the environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment