If you're looking to add machine learning to your Python development, Jack Wallen shows you how to quickly install TensorFlow on Ubuntu Desktop 20.04.
TensorFlow is an open source development platform for machine learning (ML). With this software platform, you'll get a comprehensive collection of tools, libraries, and various resources that allow you to easily build and deploy modern ML-powered applications. Beginners and experts alike can make use of this end-to-end platform, and create ML models to solve real-world problems.
How do you get started? The first thing you must do is get TensorFlow installed on your machine. I'm going to show you how to make that happen on Ubuntu Desktop 20.04.
SEE: Top 5 programming languages for systems admins to learn (free PDF) (TechRepublic)
What you'll need
- A running instance of Ubuntu Desktop 20.04
- A user with sudo privileges
How to install Python
The first thing to be done is the installation of the necessary dependencies. It just so happens these are all about Python. Log in to your desktop and install the dependencies with the command:
sudo apt-get install python3 python3-venv python3-dev -y
Python should now be installed, so you're ready to continue on.
How to install TensorFlow
How we install TensorFlow is from within a Python virtual environment. Create a new directory to house the environment with the command:
Change into that newly created directory with the command:
Next, create the Python virtual environment with the command:
python3 -m venv venv
Once the above command completes, we must then activate the virtual environment, using the source command like so:
After you activate the environment, your command prompt should change, such that it begins with (venv) (Figure A).
Next, we're going to upgrade Pip with the command:
pip install --upgrade pip
We can now install TensorFlow with the command:
pip install --upgrade tensorflow
TensorFlow should now be installed on your system. To verify, issue the command:
python -c 'import tensorflow as tf; print(tf.__version__)'
The command will return the TensorFlow version number (Figure B).
Make sure, when you're done working, that you deactivate the Python virtual environment with the command:
And there you have it, you've successfully installed TensorFlow on Ubuntu Desktop 20.04 and are ready to start adding machine learning to your builds.
Subscribe to TechRepublic's How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
How to become a developer: A cheat sheet (TechRepublic)
Kubernetes security guide (free PDF) (TechRepublic)
Linux file and directory management commands (TechRepublic Premium)
Linux, Android, and more open source tech coverage (TechRepublic on Flipboard)