How to Create a Tensorflow Environment in Jupyter Notebook and Use it?

Anaconda will enable you to create virtual environments and installl packages needed for data science. With virtual environments, you can install specific package versions for a particular project or a tutorial without worrying about version conflicts.

First, download Anaconda for your system and choose your required Python version.

On downloading and installing Anaconda, you get Python, Jupyter Notebook, conda, and hundreds of other open-source packages.

Conda is an open-source package management system and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs, and updates packages and their dependencies. Conda easily creates, saves, loads, and switches between environments on your local computer. It was created for Python programs, but it can package and distribute software for any language.

Conda as a package manager helps you find and install packages. If you need a package that requires a different version of Python, you do not need to switch to a different environment manager, because conda is also an environment manager.

With just a few commands, you can set up a totally separate environment to run that different version of Python, while continuing to run your usual version of Python in your normal environment.

Here are some helpful commands using conda:

# update conda in your default environment 
$ conda upgrade conda
$ conda upgrade --all
# create a new environment with conda
$ conda create -n [my-env-name]
$ conda create -n [my-env-name] python=[python-version]
# activate the environment you created
$ source activate [my-env-name]
# take a look at the environment you created
$ conda info
$ conda list
# install a package with conda and verify it's installed
$ conda install numpy
$ conda list
# take a look at the list of environments you currently have
$ conda info -e
# remove an environment
$ conda env remove --name [my-env-name]

Creating virtual environments with Conda

Let us see how to create a Tensorflow virtual environment using conda:

Step1: Open up your Anaconda Prompt command line, bash, or shell terminal.

Then type the following command to create an environment.

conda create -n tensorflow-environment pip python=3.8.8

The command above tells conda to create a new environment named “tensorflow-environment” using the latest version 3.8.8 of python.

It will ask you to proceed with the installation of the new packages or not: once you select ‘y’ for yes, it will download the required packages for you!

Step2: For us to be able to use our newly created environments we need to activate them on the command line.

The command for activating the environment goes like given in your console:

conda activate tensorflow-environment

Once your environment is activated, your prompt changes immediately, looking like this:

Now you are inside your newly created tensorflow-environment!!

Step3: After you activate it, you can install any package you need in this environment.

For example, I am going to install Tensorflow in this environment. The command to do so:

conda install -c conda-forge tensorflow

Once TensorFlow is installed on your tensorflow-environment, your prompt changes immediately, looking like this:

It will again ask you to proceed with the installation of the new packages or not: once you select ‘y’ for yes, it will download the required packages for you and then be done!!

.

.

Now you have successfully installed Tensorflow. Congratulations!! 😀

Step4: Now comes the step to set this conda environment on your jupyter notebook, to do so you need to install ipykernel.

conda install -c anaconda ipykernel

It will again ask you to proceed with the installation of the new packages or not: once you select ‘y’ for yes, it will download the required packages for you and then be done!!

After installing this, type below command

python -m ipykernel install — user — name tensorflow-environment

Note: Have a look at two hyphens before user and name in the above command. 🤓

Using the above command, you now have the newly created tensorflow environment in your Jupyter notebook.

Step 5: Now check your Jupyter Notebook, to see the shining “tensorflow-environment” on the right.

Click on “tensorflow-environment” under the New →Notebook tab.

Voila!! 😄

Thanks for reading ❤

For any suggestions or queries, leave your comments below and follow for updates.

If you liked the article, please hit the 👏 icon to support it. This will help other Medium users find it. Share it, so that others can read it!

Happy Learning! 😊

--

--

--

Data Analyst at Infosys Ltd., AI Engineer, MSc. Statistics SPPU.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Software Engineering Principles To Live By

Set and use Zsh as default shell in WSL on Windows 10 the right way

Least party I project car.

Can Tim Berners-Lee’s Solid Take on the Big 5?

Get area key arrive center report.

Agile Development: My Experience as a Scrum Master

Omnichannel for Customer Service — Control Session and Application tabs

Manual or Automated Testing? — The million dollar question !

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Priyanka Dandale

Priyanka Dandale

Data Analyst at Infosys Ltd., AI Engineer, MSc. Statistics SPPU.

More from Medium

Measuring the carbon footprint of your Python applications

Computational chemistry whith RDKit, PubChemPy, Pandas and Python.

Deciding who the Tennis GOAT is with the help of Python

Digging through Jeopardy! Questions using Python and Natural Language Processing