Running Tensorflow in Jupyter Notebook
I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment. Here is what I did. In Anaconda, I created an environment called tensorflow as follows
conda create -n tensorflow
Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment
(tensorflow) SFOM00618927A:dl i854319$ conda list # packages in environment at /Users/i854319/anaconda/envs/tensorflow: # appdirs 1.4.3 appnope 0.1.0 py36_0 beautifulsoup4 4.5.3 py36_0 bleach 1.5.0 py36_0 cycler 0.10.0 py36_0 decorator 4.0.11 py36_0 entrypoints 0.2.2 py36_1 freetype 2.5.5 2 html5lib 0.999 py36_0 icu 54.1 0 ipykernel 4.5.2 py36_0 ipython 5.3.0 py36_0 ipython_genutils 0.2.0 py36_0 ipywidgets 6.0.0 py36_0 jinja2 2.9.5 py36_0 jsonschema 2.5.1 py36_0 jupyter 1.0.0 py36_3 jupyter_client 5.0.0 py36_0 jupyter_console 5.1.0 py36_0 jupyter_core 4.3.0 py36_0 Keras 2.0.2 libpng 1.6.27 0 markupsafe 0.23 py36_2 matplotlib 2.0.0 np112py36_0 mistune 0.7.4 py36_0 mkl 2017.0.1 0 nbconvert 5.1.1 py36_0 nbformat 4.3.0 py36_0 notebook 4.4.1 py36_0 numpy 1.12.1 numpy 1.12.1 py36_0 openssl 1.0.2k 1 packaging 16.8 pandas 0.19.2 np112py36_1 pandocfilters 1.4.1 py36_0 path.py 10.1 py36_0 pexpect 4.2.1 py36_0 pickleshare 0.7.4 py36_0 pip 9.0.1 py36_1 prompt_toolkit 1.0.13 py36_0 protobuf 3.2.0 ptyprocess 0.5.1 py36_0 pygments 2.2.0 py36_0 pyparsing 2.1.4 py36_0 pyparsing 2.2.0 pyqt 5.6.0 py36_2 python 3.6.1 0 python-dateutil 2.6.0 py36_0 pytz 2017.2 py36_0 PyYAML 3.12 pyzmq 16.0.2 py36_0 qt 5.6.2 0 qtconsole 4.3.0 py36_0 readline 6.2 2 scikit-learn 0.18.1 np112py36_1 scipy 0.19.0 np112py36_0 setuptools 34.3.3 setuptools 27.2.0 py36_0 simplegeneric 0.8.1 py36_1 sip 4.18 py36_0 six 1.10.0 six 1.10.0 py36_0 sqlite 3.13.0 0 tensorflow 1.0.1 terminado 0.6 py36_0 testpath 0.3 py36_0 Theano 0.9.0 tk 8.5.18 0 tornado 4.4.2 py36_0 traitlets 4.3.2 py36_0 wcwidth 0.1.7 py36_0 wheel 0.29.0 wheel 0.29.0 py36_0 widgetsnbextension 2.0.0 py36_0 xz 5.2.2 1 zlib 1.2.8 3 (tensorflow) SFOM00618927A:dl i854319$
You can see that jupyter is also installed. Now, when I open up the Python interpreter in this environment and I run the basic TensorFlow command, it all works fine. However, I wanted to do the same thing in the Jupyter notebook. So, I created a new directory (outside of this environment).
mkdir dl
In that, I activated tensorflow environment
SFOM00618927A:dl i854319$ source activate tensorflow (tensorflow) SFOM00618927A:dl i854319$ conda list
And I can see the same list of packages in that. Now, I open up a Jupyter notebook
SFOM00618927A:dl i854319$ source activate tensorflow (tensorflow) SFOM00618927A:dl i854319$ jupyter notebook
It opens up a new notebook in the browser. But when I just import basic python libraries in that, like pandas, it says «no packages available». I am not sure why is that when the same environment has all those packages and in the same directory, if I use Python interpreter it shows all packages.
import pandas --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) in () ----> 1 import pandas ModuleNotFoundError: No module named 'pandas'
Why jupyter notebook is not picking up these modules? So, Jupyter notebook doesn’t show env as the interpreter
How to install Tensorflow on the Apple M1 Notebook
You’re now watching this thread. If you’ve opted in to email or web notifications, you’ll be notified when there’s activity. Click again to stop watching or visit your profile to manage watched threads and notifications.
You’ve stopped watching this thread and will no longer receive emails or web notifications when there’s activity. Click again to start watching.
Following the instructions at
I got as far as
python -m pip install tensorflow-macos
and it responded «ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none) ERROR: No matching distribution found for tensorflow-macos»
I’d be grateful for any suggestions
Copy to clipboard
Share this post
Copied to Clipboard
I am encountering the same problem with every approach I take. Why can’t you all just work in the beta and try to give us an ETA? All you have done is made the repository questions read only. This might just make me switch over to a Windows machine.
See also https://stackoverflow.com/questions/56604348/how-to-install-tensorflow-2-0-on-mac-or-linux. This covers the efforts of several developers to use several methods to get ML working on a Mac — all have run into dead-ends.
Accepted Reply
Thanks for your answer, but my Python is 3.8.5. Calling ‘python3’ causes the same error.
python3 -m pip install tensorflow-macos
ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none)
ERROR: No matching distribution found for tensorflow-macos
Copy to clipboard
Share this post
Copied to Clipboard
Post marked as solved
Replies
python -m pip install tensorflow-macos will run Python 2 and ask it to install tensorflow which is why you’re getting the error that there is no such distribution. You should change the command instead to python3 -m pip install tensorflow-macos and it will work.
If it doesn’t that means there is no python 3 in your system (which you can get from Anaconda or just brew install python3 )
For more instructions on Tensorflow installation, you should follow this link : https://www.tensorflow.org/install/pip#macos
Copy to clipboard
Share this post
Copied to Clipboard
Post not yet marked as solved Up vote reply of Lord-V15 Down vote reply of Lord-V15
Also, the recently published tensorflow-metal plugin for GPU support in Tf-macOS will only work in macOS 12.0+ so please don’t try that on Big Sur at it won’t work/will be unstable.
Thank you very much for your help Lord-V15 since python3 -m pip install tensorflow-macos has done the job very well!
Thanks for your answer, but my Python is 3.8.5. Calling ‘python3’ causes the same error.
python3 -m pip install tensorflow-macos
ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none)
ERROR: No matching distribution found for tensorflow-macos
Copy to clipboard
Share this post
Copied to Clipboard
Post marked as solved
Compile from Source guideline:
Copy to clipboard
Share this post
Copied to Clipboard
Any way to make this work inside a Conda environment?
Thanks, Pummelchen! I’ll try that.
Copy to clipboard
Share this post
Copied to Clipboard
Post not yet marked as solved Up vote reply of rodmclaughlin Down vote reply of rodmclaughlin
I got locked out of my Apple account for a month — I can’t remember why, but I’ve only just got back in. Meanwhile, I’ve managed to get Tensorflow working on a MacPro M1 — NO THANKS TO APPLE.
Copy to clipboard
Share this post
Copied to Clipboard
Post not yet marked as solved Up vote reply of rodmclaughlin Down vote reply of rodmclaughlin
Please, I need help to run M1 native Python again!
I’d been successfully running M1 native Python code on a MacBook Pro (13-inch, M1, 2020) using Jupyter Notebook, but since 10/13/2021 the notebook kernel dies as soon as the M1 CPU is used intensively. The .py version of the same code aborts too. I have formatted the MacBook several times, followed the instructions on https://developer.apple.com/metal/tensorflow-plugin/ and the problem persists. I am running macOS Big Sur 11.6. As a remedy I am now running the same code on Anaconda (Rosetta) and it is taking 50% more time. We have more than 50 data scientists in our company and I am leading a research on CoreML and the adoption of the new MacBook Pro as a standard platform to our developers. I would appreciate very much any help from Apple support or the developers community.
The test code is as follows:
import tensorflow as tf print(«Num GPUs Available: «, len(tf.config.experimental.list_physical_devices(‘GPU’)))
%%time import tensorflow.compat.v2 as tf import tensorflow_datasets as tfds
from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution()
(ds_train, ds_test), ds_info = tfds.load( ‘mnist’, split=[‘train’, ‘test’], shuffle_files=True, as_supervised=True, with_info=True, )
def normalize_img(image, label): «»»Normalizes images: uint8 -> float32 .»»» return tf.cast(image, tf.float32) / 255., label
ds_train = ds_train.map( normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_train = ds_train.cache() ds_train = ds_train.shuffle(ds_info.splits[‘train’].num_examples) ds_train = ds_train.batch(batch_size) ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)
ds_test = ds_test.map( normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_test = ds_test.batch(batch_size) ds_test = ds_test.cache() ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)
model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(32, kernel_size=(3, 3), activation=’relu’), tf.keras.layers.Conv2D(64, kernel_size=(3, 3), activation=’relu’), tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
tf.keras.layers.Flatten(), tf.keras.layers.Dense(128, activation=’relu’),
tf.keras.layers.Dense(10, activation=’softmax’) ]) model.compile( loss=’sparse_categorical_crossentropy’, optimizer=tf.keras.optimizers.Adam(0.001), metrics=[‘accuracy’], )
model.fit( ds_train, epochs=12, validation_data=ds_test, )
How to Install TensorFlow in Jupyter Notebook

As a data scientist, you may have heard about the powerful machine learning framework called TensorFlow. TensorFlow is an open-source software library developed by Google that allows you to build and train machine learning models. In this blog post, we will show you how to install TensorFlow in Jupyter Notebook, a popular web-based interactive development environment for data science.
Tired of the complexities of installing TensorFlow in Jupyter Notebook? Try Saturn Cloud for free and to set up your data science environment effortlessly!
Step 1: Install Jupyter Notebook
Now that we have TensorFlow installed, we need to install Jupyter Notebook so we can start using it. In the same terminal window, type the following command:
conda install jupyter
This will download and install Jupyter Notebook in your environment.
Step 2: Launch Jupyter Notebook
With TensorFlow and Jupyter Notebook installed, we can now launch Jupyter Notebook. In the same terminal window, type the following command:
jupyter notebook
This will open Jupyter Notebook in your default web browser. You should see a list of files and folders in your home directory. To create a new notebook, click on the New button in the top right corner and select Python 3 under Notebooks .

Step 3: Install TensorFlow
With our new environment created, we can now install TensorFlow. There are two ways to install TensorFlow: using pip or using conda. We recommend using conda as it will automatically install all the necessary dependencies. Create a new cell in your Jupyter notebook and run the command below:
!pip install tensorflow
This will download and install the latest version of TensorFlow in your environment. If your machine support GPU, make sure to Install the NVIDIA GPU driver if you have not and verify it by nvidia-smi . At the end, you can run the following command:
!pip install tensorflow[and-cuda]
Step 4: Test TensorFlow
To test if TensorFlow is working correctly, we can create a simple program that adds two numbers using TensorFlow. In your new notebook, type the following code:
import tensorflow as tf a = tf.constant(2) b = tf.constant(3) c = tf.add(a, b) with tf.Session() as sess: result = sess.run(c) print(result)
This program creates two constants, a and b , and adds them together using TensorFlow’s add function. The result is then printed to the console.
To run the program, click on the Run button in the toolbar or press Shift+Enter . You should see the result, 5 , printed to the console.
Congratulations, you have successfully installed TensorFlow in Jupyter Notebook!
Tired of the complexities of installing TensorFlow in Jupyter Notebook? Try Saturn Cloud for free and to set up your data science environment effortlessly!
Conclusion
In this blog post, we have shown you how to install TensorFlow in Jupyter Notebook using Anaconda. By following these simple steps, you can start building and training machine learning models using TensorFlow in Jupyter Notebook. Remember to create a new environment specifically for TensorFlow to avoid conflicts with other Python packages.
- Intro to Tensorflow
- Mastering deep learning with Tensorflow
About Saturn Cloud
Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.
Как установить tensorflow в jupiter notebook
Оптимизируйте свои подборки Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Установите ТензорФлоу 2
TensorFlow протестирован и поддерживается в следующих 64-битных системах:
- Питон 3.8–3.11
- Ubuntu 16.04 или новее
- Windows 7 или более поздняя версия (с распространяемым пакетом C++ )
- macOS 10.12.6 (Sierra) или новее (без поддержки графического процессора)
- WSL2 через Windows 10 19044 или выше, включая графические процессоры (экспериментальная версия)
# Requires the latest pippip install --upgrade pip
# Current stable release for CPU and GPUpip install tensorflow
# Or try the preview build (unstable)pip install tf-nightly
