In this tutorial, we’ll guide you through the essential steps of building a TensorFlow and a PyTorch working enrivonment on your local machine. For the course we'll be using TensorFlow, but PyTorch is also a very popular framework that you might encounter in the future.

System requirements

• Windows 7, 8 and 10, or Ubuntu Linux 14.04 and 16.04.
• NVIDIA graphics card with CUDA compatibility higher than version 3.0. Check out CUDA gpu for your card’s compatibility. Laptops are usually equipped with NVIDIA GeForce or Quadro graphics cards.
• Note: Because Mac doesn't have NVIDIA GPU, you can't install a GPU version of TensorFlow. However, a CPU version is available in case you want to debug your code and run it on the cloud. An official MAC OS X installation guide is proivded by TensorFlow official document: https://www.tensorflow.org/install/install_mac.

Installation Guide

Note: The process is time-consuming/complex for starters, so please prepare an external power supply if necessary. For reference, an official instruction is here: https://www.tensorflow.org/install/.

Step 1: Anaconda Installation

Anaconda is a data science platform using Python. It also provides a Python package manager that lets you install, update and remove packages.

• Install Anaconda to your local computer. If you have installed Python before, the Anaconda installer will prompt you whether you want to use Anaconda Python as your system default Python interpreter. It’s recommended that you use Anaconda Python as your system default Python.
• Check if Anaconda is correctly installed:
• Windows: open a Windows command prompt window by pressing win+R and typing cmd. In the window, type python and hit Enter. If you see the following python interpreter, which indicates it is an Anaconda interpreter, then it is finished. Type exit() to quit Python.
• Linux: open a console, and the rest is the same as in Windows.
• If python doesn't work (in which case the system doesn't find this command), or the interpreter is not the Anaconda iterpreter (in which case you've installed Python before and Anaconda is not specified as your default Python), you may choose one of the following three:
• Try reinstalling Anaconda again;
• Search "anaconda prompt" in your system and use it. This works as well.
• locate the path where the Anaconda python executable is installed, and include it into your system's PATH environment variable. Instructions on how to update PATH variable can be found here: Windows and Ubuntu. After that, type python again to test.

You can use conda list in the command window to see all the packages you’ve installed.

Step 2: Create Anaconda virtual environment

We are going to create a virtual environment on this Anaconda platform, and install necessary modules. A virtual environment is a named, isolated, working copy of Python that maintains its own files, directories and paths so that you can work with specific versions of libraries or Python itself without affecting other Python projects. Virtual environments make it easy to cleanly separate different projects and avoid problems with different dependencies and version requirements across components. The conda command is the preferred interface for managing installations and virtual environments with the Anaconda Python distribution. (managing conda environments.)

• In the command window, type conda create -n dlWorks python=3.5. If you wish, you can replace the name that we chose for the virtual environment “dlWorks” with the name of your choice. The reason we use python 3.5 version is because TensorFlow runs on python version 3.5.
• After installation, type activate dlWorks to activate the virtual enrivonment. (For Linux users, type source activate dlWorks) Your command prompt will contain the name of your environment, as in the cmd window below. (The name for this environment is ‘gpu’ rather than 'dlWorks' in this case)
• Install some necessary packages into your environment 'dlWorks' for future use. For example, to install multiple packages, type conda install pandas numpy scipy pillow matplotlib scikit-learn  in the command window.
• To list all of your virtual environments, activate/deactivate and switch between them, see managing conda environments.

Step 3: Install CUDA and GPU drivers

Compute Unified Device Architecture (CUDA) is a parallel computing platform and programming model created by NVIDIA. It harnesses the full power of graphics processing units (GPUs) for deep learning purposes.

• Install CUDA: install CUDA to your local machine. Remember the install path because it’ll be helpful during cuDNN installation. This installation can last for tens of minutes.

Step 4: Install cuDNN

cuDNN is a GPU-accelerated library for deep learning.

Note 1: This step requires you to create an NVIDIA account.

Note 2: For this step, if you're familiar with PATH environment variable setup, you can follow the official instructions provided after you login with your account. The following is a more understandable way.

• Extract the downloaded file. There would be 3 directories named ‘lib’,‘include’ and ‘bin’.
• Go to the CUDA install path. There you will also see 3 folders with the same names:

Put the contents of cuDNN into their corresponding CUDA path, i.e., move the files under cuDNN ‘bin’ directory to CUDA ‘bin’ directory, and do the same to ‘include’ and ‘bin’.

Note: If this step goes wrong, you can still install the rest, but when you initiate TensorFlow you will probably see a message: Couldn't open CUDA library cudnn.so.x. The computation speed might be compromised.

Step 5: Install TensorFlow

TensorFlow is an open source deep learning framework created and maintained by Google Brain Team. It is the most popular deep learning framework nowadays.

For windows users:

• Go to the command prompt (or anaconda command) window, and make sure that your virtual environment is active.
• If you simply want to use CPU version of TensorFlow, in the command window, type:
                pip install --ignore-installed --upgrade tensorflow

• If you want to enable GPU for TensorFlow, in the command window, type:
                pip install --ignore-installed --upgrade tensorflow-gpu


For Ubuntu users:

• Go to the command prompt (or anaconda command) window, and make sure that your virtual environment is active.
• If you simply want to use CPU version of TensorFlow, in the command window, type:
                pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl

• If you want to enable GPU for TensorFlow, in the command window, type:
                pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.3.0-cp35-cp35m-linux_x86_64.whl


Note: Always try to activate your virtual environment.

• For Ubuntu users, building from source is a better way of installing TensorFlow, but requires very complicated steps and some time. If you’re interested, visit TensorFlow build from Sources.
• Verify that TensorFlow is correctly installed. In the command window, type python, and then type:
        >>>import tensorflow as tf
>>>a = tf.constant('Hello TensorFlow!')
>>>with tf.Session() as sess:
...    print(sess.run(a))
# If you see the following output, then you're all set!
b'Hello TensorFlow!'



Step 6: (Optional) Install PyTorch(Ubuntu and OSX users only)

PyTorch is another deep learning framework for Python. Its predecessor is Torch which relys on Lua. Compared to TensorFlow, Pytorch has its own advantages such as dynamic network design.

To install PyTorch, go to the official website http://pytorch.org/ and follow the install instructions. That’s it!

ECBM E4040 Neural Networks and Deep Learning, 2017.

Columbia University