How to Install TensorFlow 2 in Anaconda

Iliya Valchanov 21 Apr 2023 2 min read

install TensorFlow 2 in Anaconda, how to install TensorFlow 2 in Anaconda, tensorflow, tensorflow 2, anaconda

How to install TensorFlow 2 in Anaconda?

TensorFlow has been a very hot framework in the past few years. With its latest version out, you must be wondering how you can install TensorFlow 2 on your machine and get it running.

In this tutorial, we’ll show you how to create a new environment, install TensorFlow, upgrade to its latest version and then add a new kernel to Jupyter.

Why Anaconda to Install TensorFlow 2?

The good thing about Anaconda is that NumPy and pandas, along with many other libraries, come automatically with it. That’s a strong plus because there’s no need to install the main packages separately as with some other software for programming in Python.

If you don’t have Anaconda installed, you can refer to our tutorial on installing the Anaconda package.

How to Check Our Current Environments

First, please open Anaconda Prompt. Most probably, the easiest way to reach it is by searching for it in your Start menu.

Type ‘conda info –envs’ like this and you will get a list of all the environments you have created before:

python3, TF2, tensorflow2, conda info --envs, install tensorflow 2

As you can see, we have 4 different environments – the base one, Python 2, Python 3, and Python 3.7 with TF2 installed on it. If you have never created an environment before, you should only have the base environment.

But that should not concern you – after all, that’s why we are here.

How to Create a New Environment in Anaconda

We have to write: “conda create –name”. Then we must include the name of the environment we want to create.

conda create --name py3-TF2.0, python 3, TF2, TensorFlow2, install tensorflow 2

You can use Anaconda not only for Python but also for other programming languages. So, it’s always advisable to include ‘Python’ or simply ‘Py’ in the name. Once you’ve done that, you can add the version of Python. In our case, that would be Python 3.

A good idea is to add any other clarification you see fit when you have more than one environment with Python 3 installed. We’ll add: ‘TF2.0’ so that we know that TensorFlow 2 is installed there. Now, all of our widely used packages, including TensorFlow 1, are in the ‘python3’ environment. However, we’ll be using this ‘py3-TF2.0’ environment only when we need TensorFlow 2, so we will include that in the name.

Finally, we must finish the line with the language we want installed and its version, so: 'python=3'.

conda create --name py3-TF2.0 python=3, python 3, TF2, TensorFlow2, install tensorflow

We get the package specifications and all that’s about to be installed.

Our new environment has been created!

Note that this process may take a couple of minutes.

How Do We Activate an Environment?

Time to enter or activate the environment, so we can manage it. So, we should write: ‘conda activate’ and the name of the environment. So, in our case, ‘conda activate py3-TF2.0’.

conda activare, python 3, TF2, TensorFlow2, tensorflow

At the beginning of the line, we see an indication that we are in fact in the new environment. Note that it is completely empty – the only packages it contains are the default ones that come with Anaconda. Everything you’ve installed before won’t be included.

And now we are ready to install TensorFlow.

We can simply type:

python 3 TF2 install tensorflow, py3, TF2

Now, to ensure there we’ve got the latest version of TensorFlow installed, we highly recommend that you also upgrade the currently installed TensorFlow version. The proper command is:

pip install –upgrade tensorflow

Finally, we must make sure we see the kernel in Jupyter once we start it. There are different ways to go about that but the easiest one is to go back to your base environment and install two packages: “nb_conda_kernels” and “ipykernel”. To go back to the base environment we must deactivate the current environment by writing: ‘conda deactivate py3-TF2.0’ Now you will be in the base environment. To install ‘ipykernel’, please write: ‘pip install ipykernel’

Then to install ‘nb_conda_kernels’, please write: ‘conda install nb_conda_kernels’

These two lines should be sufficient for you to see your newly installed kernel in Jupyter.

To make sure everything is working, open Jupyter, select ‘Kernel -> Change kernel’ from the ribbon and choose our preferred kernel.

change kernel python 3, python 3, TF2, TensorFlow2, tensorflow

We prefer the newly created kernel: Py3-TF2.0. Once you choose it you will be all set!

And there you have it. Enjoy deep learning in TensorFlow 2!

Ready to Take the Next Step Towards a Career in Data Science?

Now that you know how to install Tensorflow 2 in Anaconda, it's time to take your deep learning skills to the next level. Enroll in our Deep Learning with TensorFlow 2 course or take Convolutional Neural Networks with TensorFlow in Python. Explore other courses and further enhance your data science skills with our Data Scientist Career Track.

Sign up for our program for free and try a selection of our courses with the free subscription. Upgrade to a premium plan to access the full courses library.

GRAB 1 OF 200 ANNUAL PLANS UP TO
72% OFF

Iliya Valchanov

Co-founder of 365 Data Science

Iliya is a finance graduate with a strong quantitative background who chose the exciting path of a startup entrepreneur. He demonstrated a formidable affinity for numbers during his childhood, winning more than 90 national and international awards and competitions through the years. Iliya started teaching at university, helping other students learn statistics and econometrics. Inspired by his first happy students, he co-founded 365 Data Science to continue spreading knowledge. He authored several of the program’s online courses in mathematics, statistics, machine learning, and deep learning.

GRAB 1 OF 200 ANNUAL PLANS UP TO
72% OFF
Top