If you’re trying to install Tensorflow on Ubuntu 17.10
Hello everyone If you are new with Tensorflow and your machine running on Ubuntu 17.10 ( 17.04 might work ) I hope my article may help you pass through the nightmare of installation ^^
Let’s Get Start
Checklist
- Using Ubuntu 17.10?: YES
- Using Python 3.6+ as Programming Language?: YES
- Have an Nvidia gpu card? : YES
- Don’t want to build from source? : YES
Step 1 Installing CUDU-9.0
For version 9.1 it’s not work for Tensorflow v1.6.0
You can get CUDA Toolkit 9.0 from the link below
https://developer.nvidia.com/cuda-90-download-archive
but, you have to replace at line 4 to
sudo apt-get install cuda=9.0.176–1
keep an eyes on this change because cuda always suggest you a newest version but in our case it’s not fit for Tensorflow
Step 2 Add LD_LIBRARY_PATH
I love to use zsh as my shell but generally, people always use bash as default
So, when you see zsh just replace it to your shell (or bash)
let’s edit the rc file
sudo vim ~/.zshrc
then, add these line at the end of your file
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/extras/CUPTI/lib64
Well, every time after you modified the ‘rc’ file you have to type the command
or restart your terminal by close and reopen
source ~/.zshrc
Alright, you have pass importantly step let’s go beyond!
step 3 Installing cuDNN v7.1.1
The frequently problem which we have face with this step is GCC version!
In Ubuntu 17.10 come with GCC version 7.2.0 consequently, we have a painful problem because of tensorflow only work with GCC v.6 goes down~
The Solution : Switch GCC version ^^
Following this gist: https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91
After you change your GCC version to 6 or other. it’s time to install cuDNN
Go to Nvidia website:
https://developer.nvidia.com/rdp/cudnn-download
to download you have to join a membership but don’t worry it’s free^^
Download only 3 things
- cuDNN v7.1.1 Runtime Library for Ubuntu16.04 (Deb)
- cuDNN v7.1.1 Developer Library for Ubuntu16.04 (Deb)
- cuDNN v7.1.1 Code Samples and User Guide for Ubuntu16.04 (Deb)
After downloaded, I’m quite sure you can install .deb files
(if not don’t worry, I’m here)
sudo dpkg -i libcudnn7_7.1.1.5–1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-dev_7.1.1.5–1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-doc_7.1.1.5–1+cuda9.0_amd64.deb
Then, you test for sure that your packages already installed by…
cp -r /usr/src/cudnn_samples_v7/ $HOME
cd $HOME/cudnn_samples_v7/mnistCUDNN
make
./mnistCUDNN
you should see something like “TEST PASSED”
if you got some errors, just solve it^^ LOL
Step 4 Time to install tensorflow 1.6
I prefer to use virtualenv for some benefits, you’ll thanks yourself for decided to use it.
I create my virtualenv in my directory, for example…
virtualenv gpu_tf_env
then, to active the environment please type
source ~/path-to-env/gpu_tf_env/bin/activate
For python3 just install tensorflow via native pip3
pip install tensorflow-gpu
wait for a while I bet you it faster than build it from source TT^TT
after finished the installing it’s time to test that our effort worth!
These following code is “Hello world in Tensorflow”
import tensorflow as tf
hello = tf.constant(‘Hello, Ada from Tensorflow’)
session = tf.Session()
print(session.run(hello))
if you can run the code it mean you woke up from the nightmare already
Congratulation!! and welcome to Tensorflow World!!
I hope you will enjoy with AL and Machine Learning world best library
and also my article.
Please leave in the comment below if you have any question if I can I will answer you^^
Thank you for your time, Bye!
Reference
- Tensorflow official installation, https://www.tensorflow.org/install/
- cuDNN website, https://developer.nvidia.com/rdp/cudnn-download
- CUDA Toolkits 9.0, https://developer.nvidia.com/cuda-90-download-archive
Related Article ( Useful for you )
- https://medium.com/@andy.lane/installing-tensorflow-gpu-on-ubuntu-budgie-17-10-2eaa7761b8f7
- http://www.python36.com/install-tensorflow141-gpu/
- https://www.reddit.com/r/tensorflow/comments/7ayhle/how_to_install_tensorflow_gpu_ubuntu_1710/
- https://ghagerer.wordpress.com/2017/11/08/ubuntu-17-10-setup-for-nvidia-drivers-and-tensorflow/