Install TensorFlow with pip

 

Install TensorFlow with pip

TensorFlow 2 packages are available 

  • tensorflow —Latest stable release with CPU and GPU support (Ubuntu and Windows)

  • tf-nightly —Preview build (unstable) . Ubuntu and Windows include GPU support .

Older versions of TensorFlow 

For TensorFlow 1.x, CPU and GPU packages are separate:

  • tensorflow==1.15 —Release for CPU-only

  • tensorflow-gpu==1.15 —Release with GPU support (Ubuntu and Windows)

System requirements 

Note: Installing TensorFlow 2 requires a newer version of pip .

Hardware requirements 

  • Starting with TensorFlow 1.6, binaries use AVX instructions  which may not run on older CPUs.

  • Read the GPU support guide to set up a CUDA®-enabled GPU card on Ubuntu or Windows.

1. Install the Python development environment on your system 

Check if your Python environment is already configured:

Requires Python 3.6–3.8, pip and venv >= 19.0

$ python3 --version

$ pip3 --version


If these packages are already installed, skip to the next step.

Otherwise, install Python  , the pip package manager  , and venv  :


$ sudo apt update

$ sudo apt install python3-dev python3-pip python3-venv


Caution: Upgrading the system pip can cause problems  .

If not in a virtual environment, use python3 -m pip for the commands below. This ensures that you upgrade and use the Python pip instead of the system pip .


2. Create a virtual environment (recommended)


Python virtual environments are used to isolate package installation from the system.


Create a new virtual environment by choosing a Python interpreter and making a ./venv directory to hold it:


$ python3 -m venv --system-site-packages ./venv


Activate the virtual environment using a shell-specific command:


$ source ./venv/bin/activate  # sh, bash, or zsh


When the virtual environment is active, your shell prompt is prefixed with (venv) .

Install packages within a virtual environment without affecting the host system setup. Start by upgrading pip :

$ pip install --upgrade pip


$ pip list  # show packages installed within the virtual environment


And to exit the virtual environment later:


3. Install the TensorFlow pip package 


Choose one of the following TensorFlow packages to install from PyPI  :


  • tensorflow —Latest stable release with CPU and GPU support (Ubuntu and Windows) .

  • tf-nightly —Preview build (unstable) . Ubuntu and Windows include GPU support .

  • tensorflow==1.15 —The final version of TensorFlow 1.x.

Package dependencies are automatically installed. These are listed in the setup.py  file under REQUIRED_PACKAGES .


Virtual environment install


$ pip install --upgrade tensorflow


System Install


$ pip3 install --user --upgrade tensorflow  # install in $HOME


Verify the install:


Venv $ python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"


System install

 $ python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"


Success: If a tensor is returned, you've installed TensorFlow successfully. Read the tutorials to get started.


Package location 

A few installation mechanisms require the URL of the TensorFlow Python package. The value you specify depends on your Python version.


No comments:

Post a Comment

Office hours tomorrow(Tuesday) 5:00pm-6:00pm, 4/26/2021, 5:13 PM, English, 4/26/2021, 5:13 PM

Your assigned language is: English Classroom blog: googleclouduconn.blogspot.com 4/26/2021, 5:13 PM Office hours tomorrow(Tuesday) 5...