9951 explained code solutions for 126 technologies


python-tensorflowHow do I install Tensorflow on Ubuntu using Python?


Installing Tensorflow on Ubuntu with Python is relatively straightforward.

  1. First, you will need to install the Python package manager, pip. You can do this by running the following command in your terminal:
sudo apt-get install python-pip
  1. Next, you will need to install the virtualenv package, which will allow you to create a virtual environment in which you can install Tensorflow. To do this, you will need to run the following command:
pip install virtualenv
  1. Once the virtualenv package is installed, you can create a virtual environment by running the following command:
virtualenv --system-site-packages -p python3 ~/venv_tf
  1. Now that the virtual environment has been created, you can activate it by running the following command:
source ~/venv_tf/bin/activate
  1. You can now install Tensorflow into the virtual environment by running the following command:
pip install --upgrade tensorflow
  1. Finally, you can verify that Tensorflow has been installed correctly by running the following command:
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

The output of this command should be a random number.

Helpful links

Edit this code on GitHub