This brief tutorial shows students and new users how to install TensorFlow on Ubuntu 20.04 | 18.04.
For those who don’t know, TensorFlow is an end-to-end open-source platform for machine learning built by Google. It has comprehensive libraries and community resources that allow anyone to build machine learning programs.
When it comes to installing TensorFlow, it can be installed system-wide, in a Python virtual environment, as a Docker container, and others. The most common way to install TensorFlow is via a Python virtual environment where multiple environments can be created and managed efficiently.
If you’re a student or new user looking for a Linux system to start learning on, the most accessible place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier distribution.
Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.
To get started with installing TensorFlow, follow the steps below:
Install Python
Since using Python is the most popular way to run TensorFlow, let’s go ahead and install Python. By default, Python 3 comes with Ubuntu repositories.
To find out which version of Python is installed on Ubuntu, run the commands below:
python3 -V
That should display a similar line as below:
Output: Python 3.6.9
With Python 3.6, you’ll probably want to create a virtual environment using its venv module.
To install the python3-venv package that enables the venv module, run the commands below:
sudo apt update sudo apt install python3-venv
That should enable the Python virtual environment.
Create TensorFlow Directory
Now that you know the version of Python installed, continue below to create a directory for TensorFlow. To do that, run the commands below:
mkdir ~/TensorFlow
Next, change into the directory you create and create a Python virtual environment.
cd ~/TensorFlow python3 -m venv venv
After creating the Python environment, run the commands below to activate it.
source venv/bin/activate
Install TensorFlow
Once your environment is created and activated, use the steps below to install TensorFlow.
To install the current release, which includes support for CUDA-enabled GPU cards (Ubuntu and Windows):
pip install tensorflow
A smaller CPU-only package is also available:
pip install tensorflow-cpu
Add the –upgrade flag to the above commands to update TensorFlow to the latest version.
pip install --upgrade pip pip install --upgrade tensorflow
To verify if TensorFlow is installed, you can run the commands below:
python -c 'import tensorflow as tf; print(tf.__version__)'
The command should output the version of TensorFlow installed.
Output: 2.0.0
That tells you the version of TensorFlow installed.
Deactivate Python Environment
When you finish your Python environment, simply run the commands below to deactivate.
deactivate
That should delete the Python environment you created to run TensorFlow. For more about how to use TensorFlow, please visit its site to learn more.
https://www.tensorflow.org/learn
That should do it!
Conclusion:
- TensorFlow is a powerful open-source platform for machine learning, making it accessible for students and new users.
- Installing TensorFlow on Ubuntu using a Python virtual environment is efficient and straightforward.
- Always ensure you have the latest version of Python and the necessary packages installed to maximize compatibility.
- Activation and deactivation of the virtual environment allow for organized management of projects and dependencies.
- Explore the extensive documentation and tutorials available on the TensorFlow website for further learning and resources.
Leave a Reply Cancel reply