Installing tensorflow 2.0 for Machine Learning

Source: Deep Learning on Medium

Installing tensorflow 2.0 for Machine Learning

How to install Tensorflow into your python environment? This might be extremely simple for experienced python developers but I noticed it could be a painful process for beginners. The focus of this guide will be getting Tensorflow 2.0 installed in your python environment quickly and easily.

Step 1: Install Anaconda

If you already have anaconda installed on your PC you can skip this step but if you don’t, follow this link to download and install anaconda.

Anaconda is an open source distribution of python that will make it easy for us to install python packaged. It will also help us create python environments for installing our packages.

Step 2: Create a Python environment

Method 1: Using Anaconda Navigator

With anaconda installed you can open the anaconda navigator and create a python environment.

To create an environment click on “environments” on the left side bar. You’ll find a create button below you environments with a plus icon above it. Click on the create button and a window will pop up.

Fill in a name for your environment and for packages make sure the python checkbox is selected, select a python version for your environment. Tensorflow 2.0 requires a python version greater than 3.4 so make sure the python version you choose is above 3.4.

With all that done you can click create and Anaconda will whip up a new python environment for you. It may take a while installing all the required python packages for your environment.

When it’s done your new environment will be added to a list of your environments and you can click on it to activate it.

method 2: Using Anaconda Prompt

To create a python environment in Anaconda Prompt run the following command.

conda create -n <name> python=3.7

Anaconda will create a new python environment and install all the necessary python packages.

note: The <name> is the name of your choice for your environment and 3.7 is the python version i have selected, you can choose any version above 3.4

When it’s done, run the following command to activate your new python environment

conda activate <name>

Step 3: Install Tensorflow 2.0

Method 1: Using Anaconda Navigator

On the top right section of the navigator, There’s a drop-down list with “Installed” selected, click the drop-down arrow and select “Not installed”.This will show a list of packages you have not installed in your environment.

In the search field towards the right, search for “tensorflow” a list of related packages will be listed. select the one with the name “tensorflow” and click on the apply button below.

Anaconda will install the tensorflow packages into your python environment.

Method 2: Using Anaconda Prompt

To install tensorflow 2.0 using anaconda prompt you need to have a version of pip greater that version 19.0. To upgrade your pip version run the following command

pip install --upgrade pip

With the latest pip version installed you can run this command to install tensorflow

pip install tensorflow

Anaconda will download and install the latest version of tensorflow into your python environment.

Step 4: Testing

method 1: Using Jupyter notebook

If you have been using Anaconda navigator to follow this guide, you can install jupyter notebook in your environment by clicking on home in the left side bar.

A list of applications you can install will be shown on the right and you can click “install” under jupyter Notebook.

Anaconda will download the application and install it in your environment. When it’s done you can click on “launch” and jupyter notebook will be opened in your browser.

create a new python 3 file and run the following command to test if tesorflow has been installed correctly.

import tensorflow as tf

If the command runs with no issues then you have tensorflow installed correctly.

method 2: Using python shell

If you have anaconda prompt open just run the following command to open python shell


with the python shell idle open you can run this piece of code to test if tensorflow has been installed correctly

import tensorflow as tf

If the command runs with no issues then you have tensorflow installed correctly.

Step 5: Fixing issues

If you are installing tensorflow in an environment where you already had numpy installed, you might have ran into some issues when you test the installation.

To fix this you will have to uninstall numpy and let tensorflow install its own version of numpy.

To uninstall numpy run the following command in anaconda prompt

pip uninstall numpy

after removing numpy you’ll have to reinstall tensorflow. To remove the version you have already installed run the following command

pip uninstall tensorflow

Then follow the installation guide from step 3 to reinstall tensorflow.

something to note…

most of the information on this installation guide can be found on the official documentation for tensorflow. The docs however do not include the python environment setup.

Thanks for reading.