TensorFlow is one of the most popular machine learning frameworks. Its popularity can be attributed to its ease of use and its large community worldwide.
Like most machine learning frameworks, TensorFlow code is usually written inside Jupyter Notebooks using the Python language.
Jupyter.org defines a Jupyter Notebook as the original web application for creating and sharing computational documents. It offers a simple, streamlined, document-centric experience. Code in Jupyter Notebooks is written in cells which are usually executed sequentially.
Before one can begin writing TensorFlow code inside a Jupyter Notebook, the TensorFlow library must be installed first in the development environment.
Developers usually leverage the power of virtual environments for developing machine learning tools because virtual environments are stable, reproducible, and portable, which saves a lot of time in the future.
In this answer, we'll look at how TensorFlow can be installed in one of those environments, the Anaconda environment. Anaconda is a program for managing Python packages and environments and contains the most common data science packages.
Go to https://www.anaconda.com/download and choose the appropriate version for your operating system. Download the setup and follow the installation instructions.
After the installation, open the terminal and type the command below to confirm which version of Anaconda is installed:
conda --version
nuruddeen@nuruddeen-Latitude-E7440:~$ conda --versionconda 22.11.0nuruddeen@nuruddeen-Latitude-E7440:~$
Next, we will create a virtual environment named -tensorflow_env
using the command below:
conda create -n tensorflow_env
Activate the virtual environment:
conda activate tensorflow_env
Inside the environment, we’ll install the Jupyter Notebook and TensorFlow packages using the commands below:
conda install -c anaconda jupyterconda install -c conda-forge tensorflow
If the packages are already installed in our environment, nothing will be installed. Otherwise, they will be downloaded and installed.
To get the list of all packages installed in our environment, use the conda list
command:
conda list
Finally, after installing all the necessary packages, we launch our Jupyter Notebook from the terminal using the jupyter notebook
command:
jupyter notebook
A browser window should automatically open launching the Jupyter server. If the browser did not start automatically, open a new browser window and type http://localhost:8888
to launch the server.
To create a new notebook, select "Python3 (ipykernel)."
We can start using TensorFlow by importing it from inside our Jupyter Notebook with the following command:
import tensorflow as tf
Run the cell and TensorFlow will now be imported and is ready for use inside our notebook.
We have successfully installed TensorFlow in our environment and imported it into our notebook. We can start building our machine learning models.