Setup a Python Environment for Machine Learning and Deep Learning

Interest in Machine Learning and Deep Learning has exploded over the past decade. You see machine learning in computer science programs, industry conferences, and in many applications in daily life.

I am assuming you already know about Machine Learning, therefore I will not be explaining What and Why.

So, I find many beginners facing problems while installing libraries and setting up environment. As i have faced first time when i was trying. So this guide is totally for beginners .

In this story I will tell you how you can easily setup a python environment on your system. I am using Windows but this guide is also suitable for Ubuntu & Linux users.

After completing this tutorial, you will have a working Python environment to begin learning, and developing machine learning and deep learning software.

Let’s just get straight to the installation process. we are gonna hit the rock 😉


In this tutorial, we will cover the following steps:

  1. Download Anaconda
  2. Install Anaconda & Python
  3. Start and Update Anaconda
  4. Install CUDA Tookit & cuDNN
  5. Create an Anaconda Environment
  6. Install Deep Learning Libraries (TensorFlow & Keras)

Step 1: Download Anaconda

In this step, we will download the Anaconda Python package for your platform.

Anaconda is a free and easy-to-use environment for scientific Python.

  • 1.Install Anaconda (Python 3.6 version) Download

I am using Windows you can choose according to your OS.

Step 2: Install Anaconda

In this step, we will install the Anaconda Python software on your system.

Installation is very easy and quick once you download the setup. Open the setup and follow the wizard instructions.

#Note: It will automatically install Python and some basic libraries with it.

It might take 5 to 10 minutes or some more time according to your system.

Step 3: Update Anaconda

Open Anaconda Prompt to type the following command(s). Don’t worry Anaconda Prompt is just works same as cmd.

conda update conda
conda update --all

Step 4: Install CUDA Tookit & cuDNN

  1. Install CUDA Tookit 9.0 or 8.0 Download

Choose your version depending on your Operating System and GPU.

#Note: Kindly choose the CUDA version according to your Nvidia GPU version to avoid errors.

#Note: People with version 9.0 Download only have to install the given patch also. If you are using 8.0 or 9.1 than its not recommended for you.

2. Download cuDNN Download

Choose your version depending on your Operating System. Membership registration is required. Don’t worry you can easily create account using your email.

Put your unzipped folder in C drive as follows:


Step 5: Add cuDNN into Environment Path

  1. Open Run dialogue using (Win + R) and run the command sysdm.cpl
  2. In Window-10 System Properties, please select the Tab Advanced.
  3. Select Environment Variables
  4. Add the following path in your Environment.

Step 6: Create an Anaconda Environment

Here we will create a new anaconda environment for our specific usage so that it will not affect the root of Anaconda. Amazing!! isn’t it ? 😛

Open Anaconda Prompt to type the following commands.

  1. Create a conda environment named “tensorflow” (you can change the name) by invoking the following command:
conda create -n tensorflow pip python=3.5

2. Activate the conda environment by issuing the following command:

activate tensorflow
(tensorflow)C:> # Your prompt should change

Step 7: Install Deep Learning Libraries

In this step, we will install Python libraries used for deep learning, specifically: TensorFlow, and Keras.

  1. TensorFlow

TensorFlow is a tool for machine learning. While it contains a wide range of functionality, TensorFlow is mainly designed for deep neural network models.

=> For installing TensorFlow, Open Anaconda Prompt to type the following commands.

To install the CPU-only version of TensorFlow:

C:\> pip3 install --upgrade tensorflow

If your machine or system is only CPU supported you can install CPU version for basic learning and practice.

To install the GPU version of TensorFlow:

C:\> pip3 install --upgrade tensorflow-gpu

=> You can test the installation by running this program on shell:

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(

For getting started and documentation you can visit TensorFlow website.

2. Keras

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano.

=> For installing Keras Open Anaconda Prompt to type the following commands.

pip install keras

=> Let’s try running Mnist_Mlp.Py in your prompt. you can use other examples as well.

Open Anaconda Prompt to type the following commands.

activate tensorflow

For getting started and documentation you can visit Keras website.

Congratulations ! 😉 You have successfully created the environment using TensorFlow, Keras (with Tensorflow backend) over GPU on Windows !

There are some other famous libraries you can use like Theano, Caffe2 , Pytorch as per on your choice and use.

If you enjoyed this story, please click the 👏 button and share to help others find it. Feel free to leave a comment.