TensorFlow installation depends on your operating system and whether you want CPU or GPU support
TensorFlow is an open-source machine learning library developed by Google. You install it using Python's package manager, pip, which takes about five minutes on most machines. The process differs slightly between Windows, macOS, and Linux, and you have the option to use either CPU processing (simpler, slower) or GPU processing (faster, requires additional setup).
Before you start, you need Python 3.9 or later installed on your computer. You can check your Python version by opening a terminal or command prompt and typing python --version. If you don't have Python, download it from python.org and run the installer.
Key Takeaways
- TensorFlow installs through pip in a single command after you have Python 3.9 or later on your machine.
- CPU installation works on any computer but runs slower; GPU installation requires an NVIDIA graphics card and additional drivers.
- Creating a virtual environment before installation keeps TensorFlow separate from other Python projects and prevents version conflicts.
- After installation, you can verify it worked by opening Python and importing TensorFlow with a single line of code.
- GPU setup requires CUDA and cuDNN libraries from NVIDIA, which adds 30 minutes to an hour of setup time.
CPU installation on Windows, macOS, or Linux
CPU installation is the fastest route and works on any machine. Open your terminal (macOS or Linux) or command prompt (Windows) and create a virtual environment first. Type python -m venv tensorflow-env to create a folder called tensorflow-env that will hold TensorFlow separate from your other Python projects.
Activate the virtual environment. On macOS or Linux, type source tensorflow-env/bin/activate. On Windows, type tensorflow-env\Scripts\activate. Your command prompt should now show (tensorflow-env) at the start of each line.
With the virtual environment active, install TensorFlow by typing pip install tensorflow. This downloads and installs TensorFlow and all its dependencies. The download is about 500 MB and usually completes in two to five minutes depending on your internet speed.
GPU installation for NVIDIA graphics cards
GPU installation is faster during training but requires an NVIDIA graphics card and two additional libraries: CUDA and cuDNN. AMD and Intel graphics cards are not currently supported by TensorFlow's standard installation. Check whether your card is NVIDIA by opening Device Manager on Windows (search "Device Manager" in the Start menu) or System Report on macOS (Apple menu > About This Mac > System Report).
Download CUDA from nvidia.com/cuda-downloads. Select your operating system and follow the installer. CUDA is about 3 GB and takes 10 to 20 minutes to download and install. After CUDA finishes, download cuDNN from nvidia.com/cudnn. You will need to create a free NVIDIA account. Extract the cuDNN files and copy them into your CUDA installation folder — the installer will tell you where CUDA is installed.
Once CUDA and cuDNN are in place, create and activate a virtual environment as described above, then type pip install tensorflow[and-cuda]. This installs TensorFlow with GPU support. The download is larger than CPU-only TensorFlow and may take 10 to 15 minutes.
Verifying the installation worked
After pip finishes, verify that TensorFlow installed correctly. With your virtual environment still active, type python to open the Python interpreter. You should see a prompt that looks like >>>.
Type import tensorflow as tf and press Enter. If no error appears, TensorFlow is installed. Type print(tf.__version__) to see which version you have. Type exit() to close the Python interpreter and return to your command prompt.
If you installed GPU support, you can check whether TensorFlow sees your graphics card by typing python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))" in your command prompt. If your GPU is detected, you will see a list with your graphics card's name. If the list is empty, GPU setup did not complete correctly — check that CUDA and cuDNN are in the right folders.
Troubleshooting common installation problems
If pip says "command not found" or "is not recognized", Python is not in your system path. Reinstall Python and check the box that says "Add Python to PATH" during installation. On macOS, you may need to use python3 instead of python and pip3 instead of pip.
If you see an error about conflicting package versions, your virtual environment may have old packages. Delete the tensorflow-env folder and create a new one from scratch. If TensorFlow imports but your GPU is not detected, check that CUDA version matches what TensorFlow expects — the error message usually tells you which version you need. Visit tensorflow.org/install/source for the exact CUDA and cuDNN versions that match your TensorFlow version.
If installation is very slow, your internet connection may be the bottleneck, or pip may be downloading from a slow server. You can speed it up by typing pip install -i https://pypi.tsinghua.edu.cn/simple tensorflow to use a faster mirror, though this works best in China and parts of Asia.
Using TensorFlow after installation
After you verify the installation, you can start using TensorFlow in your Python scripts. Every time you want to work with TensorFlow, activate your virtual environment first. On macOS or Linux, type source tensorflow-env/bin/activate. On Windows, type tensorflow-env\Scripts\activate. Then open your Python editor or IDE and import TensorFlow with import tensorflow as tf at the top of your script.
If you use an IDE like Visual Studio Code or PyCharm, you may need to tell it which Python interpreter to use. Look for a settings option to select your interpreter and point it to the Python inside your tensorflow-env folder. On Windows, that path is tensorflow-env\Scripts\python.exe. On macOS or Linux, it is tensorflow-env/bin/python.
Frequently Asked Questions
Do I need a GPU to use TensorFlow?
No. CPU installation works on any computer and is fine for learning and small projects. GPU is only faster for large training jobs that would take hours or days on CPU. Start with CPU installation and upgrade to GPU later if you need the speed.
Can I install TensorFlow without a virtual environment?
Yes, but it is not recommended. Installing directly into your system Python can cause version conflicts with other projects. A virtual environment takes 30 seconds to create and prevents these problems.
What if I have an AMD or Intel graphics card?
TensorFlow's standard installation does not support AMD or Intel GPUs. You can use CPU processing, or you can explore alternative libraries like PyTorch or JAX, which have better support for non-NVIDIA hardware. For now, stick with CPU installation.
How much disk space does TensorFlow need?
CPU-only TensorFlow takes about 1 to 2 GB including Python and dependencies. GPU installation with CUDA and cuDNN takes 5 to 10 GB. Make sure you have at least 15 GB free to be safe.
Can I update TensorFlow after installation?
Yes. Activate your virtual environment and type pip install --upgrade tensorflow. This downloads the latest version. Check tensorflow.org/install for release notes before upgrading, as major version changes sometimes break older code.