9951 explained code solutions for 126 technologies


python-tensorflowHow do I install TensorFlow for Python?


Installing TensorFlow for Python can be done in a few simple steps.

  1. Install the latest version of Python.
  2. Download and install TensorFlow from the official website.
  3. Create a virtual environment and activate it.
python -m venv env
source env/bin/activate
  1. Install the TensorFlow package inside the virtual environment.
pip install --upgrade tensorflow
  1. Confirm that the installation was successful by importing the TensorFlow library.
python
import tensorflow as tf
print(tf.__version__)

Output example

2.2.0

  1. Test a simple TensorFlow program.
import tensorflow as tf

# Create a constant op
# This op is added as a node to the default graph
hello = tf.constant("Hello, TensorFlow!")

# start a TF session
sess = tf.Session()

# run the op and get result
print(sess.run(hello))

Output example

b'Hello, TensorFlow!'

Helpful links

Edit this code on GitHub