Installing Tensorflow and Anaconda Python : Deep Learning ENV

Getting started with Deep Learning and not sure which framework to choose? Well let me tell you. You need Tensorflow – the deep learning framework from Google that went open source last November. With Tensorflow anyone with basic python knowledge can write magic spells aka deep learning networks . So let’s say you want to get started with tensorflow and you also want to avoid the hassle of going through all the dependency installations – you can use Anaconda. But, tensorflow isn’t available in conda channels yet. How to do it then? Let’s find out with Anaconda!

What we need

  • First of all you need to have Anaconda installed. You can get it from here for your OS. – https://www.continuum.io/downloads

  • If you’re on Windows or macOS, you can just download and install using the graphical installer.

  • However if you’re on a Linux Distribution, you’ll need to download the installer script and run it from the command line. ( Terminal / Konsole etc. ) Instructions are given on the website.

  • The download is heavy, so in case you have a slow internet connection, wait.

Adding Anaconda to path in macOS and Linux Distributions

If you’re on either macOS or on a Linux Distro. you need to add Anaconda to your path in order for conda and other modules to work. How ?

On macOS

  • Open Terminal

  • Then open your .bash_profile file with your preferred text editor. Or you can just use nano, whatever seems convenient to you. So let’s use nano. Use the following command –

nano .bash_profile
  • Now scroll down to the very end of the file. check if you see the following line :
export PATH="path_to_anaconda_installation/bin:$PATH"

For example on my Mac it looks like –

export PATH="/Users/shawon/anaconda/bin:$PATH"
  • If it’s not there, add it. Save the file using ctrl + o and then exit using ctrl + x. Done. Close the terminal window and then open another one. Or instead of opening another terminal window you can use –
source .bash_profile

On a Linux Distro (I’m using Ubuntu here)

  • Same drill, open Terminal.
  • nano may not be installed by default. You can install it using –
sudo apt-get install nano
  • Then do the same like macOS instructions. But a slight change. open .bashrc instead of .bash_profile

  • The rest is same.

Testing

  • Open up the command line, type in python. It should look something like the following (version number depends on which version of Anaconda you installed)
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
  • If you don’t see something similiar, check again in .bash_profile or .bashrc if path was set correctly.

Done! Now let’s create a seperate env for our work!

It’s always a good idea to keep seperate work environment for all your python development. So we’re going to create one for deep learning. Command for creating a conda env is as follows

conda create --name  env_name  python-ver  packages_to_install

So let me explain the bits.
env_name means what you’re going to name your env. Pick a name that fast to type in.

python-ver means which version of python you want to be installed for this env. If you want to choose the the one that came with Anaconda . e.g – 3.6.0 you can leave it blank.

packages_to_install : You’ll need packages with your env right? so name them here with spaces. e.g. numpy, jupyter and so on.

Creating the env

Open up command line and type in the following , we will name our env as env_tf . You can choose whatever you like. I’m using python 3.5.2

conda create --name env_tf python=3.5.2 numpy jupyter matplotlib

Let it download and install. Enter y when it prompts for permission.

Activating the env

Command syntax for activating a conda env is as follows –

source activate env_name

So for our env we do the following –

source activate env_tf

Now our env is activated, we can roll out!

Now , we install tensorflow from pypi using pip

Use the following command –

pip install tensorflow

Let it download and install.

Installation done. Let’s check.

Fire up your command line and type in python and press enter / return key.

Now type in the following code to check –

import tensorflow as tf
s = tf.Session()
print(s)

It should look like this –

Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> s = tf.Session()
2017-06-28 21:32:17.764741: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-28 21:32:17.764770: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-28 21:32:17.764779: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-28 21:32:17.764786: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>>

So all done!

Now we are done creating our basic env and installing tensorflow, we can finally start digging deep into deep learning. You can look into tensorflow documentation for more information and tutorials. Also Tensorflow for poets lab sessions by Google are also great. You can have a look at them.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s