How To Install TensorFlow in a Virtual Environment with Anaconda

NOTE: Refer to the How To Setup Data Science Projects with Jupyter Notebooks or JupyterLab instructions for information on installing Anaconda, creating a virtual environment, and working with Python inside of VSCode (with or without Python Notebooks).

You can add TensorFlow to an environment.yml file and create a virtual environment that includes TensorFlow by following the instructions on How To Setup Data Science Projects with Jupyter Notebooks or JupyterLab.

1
name: name-of-virtual-environment
2
channels:
3
  - conda
4
  - conda-forge
5
dependencies:
6
  - python==3.12
7
  - pip==24.2
8
  - tensorflow==2.19.0
9
  # Other packages go here...

Or you can create a new virtual environment using conda and install the packages you want in that environment:

1
conda create --name tf tensorflow
2
conda activate tf

NOTE: It will take several minutes to install TensorFlow along with all of the necessary packages.

Sources: