If you’ve ever typed import tensorflow as tf inside a Jupyter Notebook and got hit with a ModuleNotFoundError, you’re not alone. This is one of the most common frustrations for beginners getting into machine learning, and it almost always comes down to one thing: TensorFlow was installed in a different environment than the one Jupyter is using.
In this guide, I’ll show you exactly how to install TensorFlow and get it working inside Jupyter Notebook, whether you’re using Anaconda Navigator, Anaconda Prompt, or VS Code. I’ll cover the full setup from scratch, including how to register your environment as a Jupyter kernel so everything connects properly.
No guesswork, no copy-paste errors — just a clean, working setup.
How Jupyter Notebook and Environments Work Together
Before we get into steps, let me explain one thing quickly — because understanding this saves you a lot of debugging time.
Jupyter Notebook doesn’t automatically see every Python environment on your machine. It only sees environments that have been registered as a kernel. A kernel is just the Python engine that runs your notebook code.
So when you install TensorFlow in environment A but Jupyter is running on environment B, the import fails — even though TensorFlow is clearly installed somewhere on your computer.
The fix is a two-part process:
- Install TensorFlow inside a specific environment
- Register that environment as a Jupyter kernel so your notebook uses it
Every method below follows this pattern. Once you understand it, everything makes sense.
Method 1: Install TensorFlow on Jupyter Using Anaconda Navigator (GUI)
This is the best method if you prefer clicking over typing commands. Anaconda Navigator gives you a visual interface to manage environments and launch Jupyter.
Step 1: Download and Install Anaconda
If you don’t have Anaconda yet, download it from anaconda.com/download. Choose the version for your operating system (Windows, macOS, or Linux) and follow the instructions.
Once installed, open Anaconda Navigator from your Start Menu (Windows) or Applications folder (macOS).
Step 2: Create a New Environment
In Anaconda Navigator:
- Click Environments in the left sidebar
- Click the Create button at the bottom
- Name your environment — I’ll call mine tf_env
- Select Python 3.11 from the dropdown (recommended for best compatibility)
- Click Create and wait for it to finish. Always create a new environment for TensorFlow. Don’t install it into your base environment — that’s your safety net, and polluting it with ML packages will cause conflicts eventually.
Step 3: Install TensorFlow in that Environment
With tf_env selected in the left panel:
- Change the package filter from Installed to Not installed
- In the search box, type
tensorflow - Check the box next to
tensorflow - Click Apply at the bottom right
- Confirm by clicking Apply again in the pop-up
Anaconda will now resolve and install TensorFlow and all its dependencies. This may take a few minutes.
⚠️ Note: The TensorFlow version in conda-forge may sometimes be slightly behind the latest pip release. If you need the absolute latest version, use Anaconda Prompt with pip install tensorflow (covered in Method 2).
Step 4: Install Jupyter in the Same Environment
While still in tf_env, search for jupyter in the packages list and install it the same way. This ensures Jupyter runs from within your TensorFlow environment.
Step 5: Launch Jupyter Notebook
- Go back to Home in the left sidebar
- At the top, change Applications on from base (root) to tf_env
- Click Launch under Jupyter Notebook
Jupyter will now open in your browser running from inside tf_env — which means TensorFlow is available.
Step 6: Test it
Open a new notebook and run:
import tensorflow as tf
print(tf.__version__)
If you see a version number, you’re done.
Method 2: Install TensorFlow on Jupyter Using Anaconda Prompt (Command Line)
This method gives you more control and installs the latest TensorFlow version using pip. I personally prefer this over the GUI because it’s faster and more predictable.
Step 1: Open Anaconda Prompt
On Windows, search for Anaconda Prompt in the Start Menu and open it. On macOS/Linux, open your regular Terminal — conda is available there once Anaconda is installed.
Step 2: Create a New Conda Environment with Python 3.11
conda create -n tf_env python=3.11
Type y and press Enter when prompted to confirm.
Step 3: Activate the Environment
conda activate tf_env
Your prompt will change to (tf_env), confirming you’re inside the environment.
Step 4: Install TensorFlow using pip
pip install tensorflow
Even inside a conda environment, use pip for TensorFlow. The conda-forge version is often outdated and can cause dependency headaches.
Step 5: Install Jupyter and ipykernel
pip install jupyter ipykernel
ipykernel is the package that allows Jupyter to communicate with Python environments. You must install it here.
Step 6: Register the Environment as a Jupyter Kernel
python -m ipykernel install --user --name=tf_env --display-name "Python (TensorFlow)"
This is the step most guides skip — and it’s the reason so many people end up with TensorFlow installed but Jupyter still can’t find it. This command tells Jupyter: “hey, there’s a Python environment here called tf_env — make it available as a kernel option.”
Step 7: Launch Jupyter Notebook
jupyter notebook
Jupyter will open in your browser.
Step 8: Select the Right Kernel
When you open a new notebook:
- Click Kernel in the top menu
- Select Change Kernel
- Choose Python (TensorFlow) — the name you set in Step 6
Step 9: Test it
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
Method 3: Install TensorFlow on Jupyter Notebook Inside VS Code
VS Code has become one of the most popular ways to work with Jupyter notebooks, especially if you’re doing a mix of scripting and notebook work. Here’s how to get TensorFlow working inside VS Code’s Jupyter environment.
What you need first
- VS Code installed — download from code.visualstudio.com
- Python extension for VS Code (install from the Extensions sidebar, ID:
ms-python.python) - Jupyter extension for VS Code (ID: ms-toolsai.jupyter)
Step 1: Create your TensorFlow environment
If you’ve already followed Method 2 above and created tf_env, skip this step. Otherwise, in your terminal (or Anaconda Prompt):
conda create -n tf_env python=3.11
conda activate tf_env
pip install tensorflow ipykernel
python -m ipykernel install --user --name=tf_env --display-name "Python (TensorFlow)"
Step 2: Open VS Code and select the environment
- Open VS Code
- Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS) to open the Command Palette
- Type Python: Select Interpreter
- Choose your tf_env conda environment from the list
You’ll see the selected interpreter in the bottom-left status bar of VS Code.
Step 3: Create or open a Jupyter Notebook
- Press Ctrl+Shift+P and type Create: New Jupyter Notebook
- A .ipynb file will open inside VS Code
Step 4: Select the kernel in the notebook
In the top-right of the VS Code notebook interface, you’ll see a kernel selector (it might say “Select Kernel” or show a Python version). Click it and choose Python (TensorFlow) — the kernel you registered earlier.
Step 5: Test it
In the first cell, run:
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
print("GPU available:", tf.config.list_physical_devices('GPU'))
You can see the output in the screenshot below.

If TensorFlow is working, you’ll see the version printed. If GPU is available, it will be listed — otherwise, you’ll see an empty list, which is completely normal for CPU-only setups.
Method 4: Install TensorFlow on Jupyter Without Anaconda (Pure pip + venv)
If you don’t use Anaconda and prefer a lightweight setup with Python’s built-in virtual environments, here’s how to do it.
Step 1: Create a virtual environment
python -m venv tf_env
Step 2: Activate it
Windows:
tf_env\Scripts\activate
macOS/Linux:
source tf_env/bin/activate
Step 3: Install TensorFlow, Jupyter, and ipykernel
pip install tensorflow jupyter ipykernel
Step 4: Register the kernel
python -m ipykernel install --user --name=tf_env --display-name "Python (TensorFlow)"
Step 5: Launch Jupyter
jupyter notebook
Select Python (TensorFlow) as your kernel when opening a new notebook.
How to Verify TensorFlow is Working in Your Notebook
Once your notebook is open and the correct kernel is selected, run this verification cell:
import tensorflow as tf
# Check version
print("TensorFlow version:", tf.__version__)
# Check available devices
print("Available devices:")
for device in tf.config.list_physical_devices():
print(" -", device)
# Run a simple computation
x = tf.constant([1.0, 2.0, 3.0])
print("\nTest tensor:", x)
print("Sum:", tf.reduce_sum(x).numpy())
What you should see:
- A TensorFlow version number (2.16.x or 2.21.x)
- At minimum, a CPU device listed
- A tensor and its sum printed without errors
If all three of those work, your setup is solid.
A Quick Working Example in Jupyter
Here’s a simple end-to-end example you can run in your notebook right after installation to confirm everything works:
import tensorflow as tf
import numpy as np
# Generate training data: y = 3x + 1
X_train = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype=float)
y_train = np.array([4.0, 7.0, 10.0, 13.0, 16.0, 19.0], dtype=float)
# Build a simple linear model
model = tf.keras.Sequential([
tf.keras.layers.Dense(units=1, input_shape=[1])
])
# Compile
model.compile(optimizer='adam', loss='mean_squared_error')
# Train
model.fit(X_train, y_train, epochs=300, verbose=0)
# Predict
test_val = 10.0
prediction = model.predict([test_val], verbose=0)
print(f"Input: {test_val}")
print(f"Predicted output: {prediction[0][0]:.2f}") # Should be close to 31.0
If this runs and prints a number close to 31.00 (since y = 3×10 + 1 = 31), your TensorFlow setup inside Jupyter is working perfectly.
Common Errors and Fixes
Error: ModuleNotFoundError: No module named ‘tensorflow’
This is the most common issue. It means Jupyter is not using the environment where TensorFlow is installed.
Fix:
- Confirm your kernel is set to Python (TensorFlow) — check the kernel selector in the top-right of your notebook
- If the kernel isn’t there, go back and run the ipykernel install command from Step 6 of Method 2
- Restart Jupyter after registering the kernel
Error: Kernel keeps dying or restarting when importing TensorFlow
Why it happens: Memory issue or a conflicting package version, often NumPy.
Fix:
pip install numpy --upgrade
pip install tensorflow --upgrade
Then restart the Jupyter kernel (not the whole notebook server, just the kernel via Kernel → Restart).
Error: TensorFlow import works in the terminal but not in Jupyter
Why it happens: Jupyter is running from a different Python environment than your terminal.
Fix: You haven’t registered the ipykernel. Run this from inside your activated environment:
python -m ipykernel install --user --name=tf_env --display-name "Python (TensorFlow)"
Then restart Jupyter and switch to the new kernel.
Error: The kernel appears to have died on VS Code
Why it happens: Usually a Python or TensorFlow version mismatch, or VS Code is pointing to the wrong interpreter.
Fix:
- Press Ctrl+Shift+P → Python: Select Interpreter
- Make sure you’re selecting the tf_env environment, not the base Python
- Reload VS Code and try again
Error: conda activate tf_env doesn’t work on macOS/Linux terminal
Fix: Initialize conda for your shell first:
conda init bash # or 'zsh' if you're using zsh
Close and reopen your terminal, then try conda activate tf_env again.
Frequently Asked Questions
Q: Do I need Anaconda to use TensorFlow with Jupyter?
No. Anaconda is convenient because it bundles Python, Jupyter, and a package manager together — but you can use a plain Python virtual environment with pip and it works just as well. Method 4 in this guide covers that exact approach.
Q: Why can’t I just install TensorFlow in the base conda environment?
You can, but I’d strongly recommend against it. The base environment is shared across all your projects. If one project needs an older TensorFlow version and another needs the latest, you’ll end up in a conflict. Isolated environments keep things clean.
Q: Can I have multiple kernels in Jupyter — one for TensorFlow, one for PyTorch?
Yes, absolutely. Each registered ipykernel shows up as a separate kernel option in Jupyter. You can create as many environments as you need and register each one.
Q: How do I remove a Jupyter kernel I no longer need?
jupyter kernelspec list # See all registered kernels
jupyter kernelspec uninstall tf_env # Remove a specific one
Q: Does this work on Google Colab too?
Google Colab already has TensorFlow pre-installed — you don’t need to do anything. Just run import tensorflow as tf in a Colab cell and it works. Colab is a great option if you want to skip local setup entirely.
Q: How do I update TensorFlow in my Jupyter environment?
Activate the environment first, then upgrade:
bashconda activate tf_env
pip install tensorflow –upgrade
Then restart your Jupyter kernel to pick up the new version.
Which Method Should You Use?
| Your Situation | Best Method |
|---|---|
| You prefer a visual interface, new to the command line | Method 1 (Anaconda Navigator) |
| You’re comfortable with the terminal, want the latest TF version | Method 2 (Anaconda Prompt + pip) |
| You code primarily in VS Code | Method 3 (VS Code + Jupyter extension) |
| You don’t have Anaconda and prefer a lightweight setup | Method 4 (pip + venv) |
All four methods end up at the same place, a working TensorFlow kernel inside Jupyter. Pick the one that fits how you work.
You may also like to read:
- TensorFlow vs PyTorch: Choose Your Enterprise Framework
- TensorFlow Ecosystem: Guide to Tools, Libraries & Deployment
- Introduction to TensorFlow 3.x: What’s New?
- How to Upgrade TensorFlow to the Latest Version

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.