How to Download & Install Tensorflow in Jupyter Notebook

โšก Smart Summary

TensorFlow installs cleanly inside an isolated Anaconda environment, which keeps Python, Jupyter and the framework resolving to one path and prevents version clashes with every other data project already living on the same machine.

  • ๐Ÿ”˜ Pick a build: The CPU package suits most learning work; the GPU build needs an NVIDIA card.
  • โ˜‘๏ธ Isolate first: A conda environment declared in a .yml file keeps dependencies reproducible.
  • โœ… Windows extra: Windows prepares the environment first, then adds TensorFlow with pip install tensorflow.
  • ๐Ÿงช Verify the path: python, jupyter and ipython must all resolve inside the same environment.
  • ๐Ÿ› ๏ธ Import test: import tensorflow as tf followed by tf.constant proves the install works.
  • ๐Ÿ”’ Reactivate: Every new session needs conda activate hello-tf before Jupyter starts.

Download and install TensorFlow in Jupyter Notebook

Installing TensorFlow with Anaconda on Windows or macOS takes one conda environment and a few commands. You will also learn how to import TensorFlow inside Jupyter Notebook, the browser-based notebook viewer.

TensorFlow Versions

TensorFlow supports computations across multiple CPUs and GPUs. It means that the computations can be distributed across devices to improve the speed of the training. With parallelization, you don’t need to wait for weeks to obtain the results of training algorithms.

For Windows users, TensorFlow provides two build variants:

  • TensorFlow with CPU support only: If your machine has no NVIDIA GPU, install this build.
  • TensorFlow with GPU support: Faster for training, but worth the setup only when you need real computational capacity.

During this tutorial, the basic version of TensorFlow is sufficient. The table below compares the two builds:

Criterion CPU build GPU build
Package tensorflow (CPU wheel) tensorflow with CUDA runtime
Hardware Any x86 or ARM processor NVIDIA card with supported CUDA
Best for Tutorials, small models Large training runs
Setup effort One command Driver, CUDA and cuDNN matching

Version note: TensorFlow 2.10 was the last release with native Windows GPU support. From 2.11 onward, Windows users run the GPU build inside WSL2 or install the CPU package. Apple Silicon Macs add tensorflow-metal for acceleration.

Note: TensorFlow does not provide CUDA GPU support on macOS.

Here is how to proceed

macOS users:

  • Install Anaconda
  • Create a .yml file to install TensorFlow and dependencies
  • Launch Jupyter Notebook

Windows users:

  • Install Anaconda
  • Create a .yml file to install dependencies
  • Use pip to add TensorFlow
  • Launch Jupyter Notebook

To run TensorFlow with Jupyter, create a dedicated environment inside Anaconda holding IPython, Jupyter and TensorFlow. Add one essential data science library as well: pandas, which manipulates data frames.

Install Anaconda

Download Anaconda version 4.3.1 (for Python 3.6) for the appropriate system.

Those versions are legacy: current TensorFlow 2.x pairs with Python 3.9 to 3.12. Since 2024 the Anaconda default channel also requires a paid licence for organisations above 200 people, so Miniconda or Miniforge with conda-forge is the free route.

Anaconda manages the libraries required for Python or R, then installs them per environment.

Create .yml file to install TensorFlow and dependencies

It includes

  • Locate the path of Anaconda
  • Set the working directory to Anaconda
  • Create the yml file (For MacOS user, TensorFlow is installed here)
  • Edit the yml file
  • Compile the yml file
  • Activate Anaconda
  • Install TensorFlow (Windows user only)

Step 1) Locate Anaconda,

The first step you need to do is to locate the path of Anaconda.

You will create a conda environment holding the libraries used throughout the TensorFlow tutorials.

Windows

If you are a Windows user, you can use Anaconda Prompt and type:

C:\>where anaconda

Anaconda Prompt output of the where anaconda command on Windows

We are interested to know the name of the folder where Anaconda is installed because we want to create our new environment inside this path. In the picture above, Anaconda sits in the Admin folder; yours will carry your own user name.

Next, you will move the working directory from c:\ to Anaconda3.

MacOS

For macOS users, open the Terminal and type:

which anaconda

Terminal output of the which anaconda command on macOS

You now create a folder inside Anaconda that will contain IPython, Jupyter and TensorFlow. The quickest way to declare those libraries is a yml file.

Step 2) Set working directory

Specify the working directory where the yml file will be created; as noted above, it sits inside Anaconda.

For macOS users:

The Terminal defaults to Users/USERNAME. In the figure below the anaconda3 path and the working directory match; macOS shows the current folder before the $. Every library is installed there.

If the path in your text editor does not match, run cd PATH in the Terminal, quoting the path when it contains spaces.

macOS Terminal showing the anaconda3 path as the working directory

Open your Terminal, and type:

cd anaconda3

For Windows users, check the folder that precedes Anaconda3:

cd C:\Users\Admin\Anaconda3

or the path “where anaconda” command gives you

Windows prompt after changing directory into Anaconda3

Step 3) Create the yml file

You can create the yml file inside the new working directory.

The file will install the dependencies you need to run TensorFlow. Copy and paste this code into the Terminal.

For MacOS user:

touch hello-tf.yml

A new file named hello-tf.yml should appear inside anaconda3

macOS Terminal creating hello-tf.yml with the touch command

For Windows user:

echo.>hello-tf.yml

A new file named hello-tf.yml should appear

Windows prompt creating hello-tf.yml with the echo command

Step 4) Edit the yml file

You are ready to edit the yml file.

For MacOS user:

You can paste the following code in the Terminal to edit the file. MacOS user can use vim to edit the yml file.

vi hello-tf.yml

So far, your Terminal looks like this

Terminal opening hello-tf.yml in the vi editor

You enter an edit mode. Inside this mode, you can, after pressing esc:

  • Press i to start editing
  • Press esc, then type :w to save
  • Press esc, then type :q! to quit without saving

Write the following code in the edit mode and press esc followed by :w

hello-tf.yml dependency list typed inside vi

Note: The file is case and indentation sensitive. Two spaces are required for each indent level.

For MacOS

name: hello-tf
dependencies:
 - python=3.6
 - jupyter
 - ipython
 - pandas
 - pip:
 - https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl

Code Explanation

  • name: hello-tf: Name of the yml file
  • dependencies:
  • python=3.6
  • jupyter
  • ipython
  • pandas: Install Python 3.6, Jupyter, IPython and pandas.
  • pip: Install a Python library
    • The wheel URL: install TensorFlow directly from the Google storage API.

Press esc followed by :q! to leave edit mode.

Saved hello-tf.yml file shown after leaving vi

For Windows User:

Windows has no vim, so Notepad is enough for this step.

notepad hello-tf.yml

Enter following into the file

name: hello-tf
dependencies:
 - python=3.6
 - jupyter
 - ipython
 - pandas

Code Explanation

  • name: hello-tf: Name of the yml file
  • dependencies:
  • python=3.6
  • jupyter
  • ipython
  • pandas: Install Python 3.6, Jupyter, IPython and pandas.

It will open the notepad, you can edit the file from here.

hello-tf.yml opened in Windows Notepad

Note: Windows users install TensorFlow in the next step; here you only prepare the conda environment.

Step 5) Compile the yml file

Compile the .yml file with the following command:

conda env create -f hello-tf.yml

Note: For Windows users, the new environment is created inside the current user directory.

It takes time and roughly 1.1 GB of disk space.

conda env create output resolving the hello-tf dependencies on macOS

In Windows

conda env create output resolving the hello-tf dependencies on Windows

Step 6) Activate conda environment

You now have two conda environments.

An isolated environment is recommended practice, because each machine learning project needs a different library set, and you can delete it when the project ends.

conda env list

conda env list showing the base and hello-tf environments

The asterisk marks the active environment. Switch to hello-tf to activate it. Modern conda uses conda activate on every platform; source activate is deprecated.

For MacOS user:

source activate hello-tf

For Windows user:

activate hello-tf

Terminal prompt after activating the hello-tf environment

Confirm every dependency resolves inside the same environment, so Python, Jupyter and TensorFlow share one prefix. If the three paths differ, rebuild the environment.

For MacOS user:

which python
which jupyter
which ipython

which python, jupyter and ipython resolving inside hello-tf on macOS

Optional: Check for an update.

pip install --upgrade tensorflow

Step 7) Install TensorFlow For Windows user

For Windows users:

where python
where jupyter
where ipython

where python, jupyter and ipython resolving inside hello-tf on Windows

Two Python environments now exist: the base one and hello-tf. Only hello-tf carries TensorFlow. In the picture, python, jupyter and ipython all resolve to the same environment, so TensorFlow is usable from a Jupyter Notebook.

Windows users install TensorFlow with pip:

pip install tensorflow

pip install tensorflow output inside the hello-tf environment

How to Import TensorFlow in Jupyter Notebook

This part is identical on both operating systems. Remember that the environment must be activated every time before you open TensorFlow.

You will proceed as follow:

  • Activate hello-tf conda environment
  • Open Jupyter
  • Import TensorFlow
  • Delete Notebook
  • Close Jupyter

Step 1) Activate conda

For MacOS user:

source activate hello-tf

For Windows user:

conda activate hello-tf

Activating the hello-tf conda environment before opening Jupyter

Step 2) Open Jupyter

After that, you can open Jupyter from the Terminal

jupyter notebook

jupyter notebook command starting the notebook server

The browser should open automatically; otherwise copy the URL printed by the Terminal, which starts with http://localhost:8888.

The dashboard lists every file in the working directory. Click New and Python 3 to create a notebook.

Note: The new notebook is automatically saved inside the working directory.

Jupyter dashboard with the New and Python 3 menu open

Step 3) Import TensorFlow

Inside the notebook, you can import TensorFlow in Jupyter Notebook with the tf alias. Click to run. A new cell is created below.

import tensorflow as tf

Notebook cell running import tensorflow as tf

Let’s write your first code with TensorFlow.

hello = tf.constant('Hello, Guru99!')
hello

A new tensor is created. Congratulations, TensorFlow now runs with Jupyter on your machine.

Notebook cell creating the Hello, Guru99 constant tensor

Step 4) Delete file

Delete the file named Untitled.ipynb from the Jupyter dashboard.

Deleting the Untitled.ipynb file from the Jupyter dashboard

Step 5) Close Jupyter

Jupyter can be closed from the notebook itself or from the terminal (Anaconda Prompt on Windows).

From Jupyter

In the main panel of Jupyter Notebook, simply click on Logout

Logout button in the Jupyter Notebook main panel

You are redirected to the log out page.

Jupyter logout confirmation page

From the terminal

Select the terminal or Anaconda Prompt and press Ctrl+C twice.

The first Ctrl+C asks you to confirm the shutdown; the second confirms it.

Terminal prompt asking to confirm the notebook server shutdown

Terminal after the Jupyter server has stopped

You have successfully logged out.

Jupyter with the main conda environment

To launch TensorFlow with Jupyter in a future session, activate the environment first:

source activate hello-tf

Without that step, Jupyter starts in the base environment and the import fails.

Jupyter started from the base conda environment without TensorFlow

FAQs

Recent TensorFlow releases support Python 3.9 through 3.12. Pin the version in your .yml file so conda resolves a matching wheel, and avoid Python builds newer than the release notes list.

TensorFlow ships officially to PyPI, so pip install tensorflow inside a conda environment is the supported route. Use conda for Python, Jupyter and pandas, then pip for the framework itself.

Run tf.config.list_physical_devices(‘GPU’) in a notebook cell. An empty list means the CPU build is active or the CUDA and cuDNN versions do not match the release requirements.

The notebook kernel is running in a different environment. Activate hello-tf before launching Jupyter, or register the environment as a kernel with python -m ipykernel install –user –name hello-tf.

Run conda env remove -n hello-tf from the base environment. Deactivate it first, then confirm with conda env list that the entry has gone and the disk space has been reclaimed.

Install tensorflow inside a native arm64 environment, then add the tensorflow-metal plugin so Keras uses the Apple GPU. Rosetta builds run but lose the acceleration entirely.

Copilot drafts .yml files, pip commands and kernel registration snippets from a plain comment, which shortens setup. Version pins still need checking against the official release notes before you run anything.

Assistants now draft training loops, suggest hyperparameter ranges and explain errors inside the notebook. That speeds up machine learning iteration, though evaluation and data quality remain human decisions.

Summarize this post with: