TensorFlow-cpu is the CPU-optimized variant of TensorFlow, an open-source machine learning framework developed by Google. It is designed for high-performance numerical computation, suitable for training and deploying machine learning models without GPU acceleration. The current version is 2.21.0, and it follows a frequent release cadence, typically aligning with the main TensorFlow project's minor and patch updates every few months.
pip install tensorflow-cpuVerified import paths — ran on the pinned version, not inferred.
This quickstart code verifies the installed TensorFlow version, checks if CPU devices are recognized, and performs a basic tensor operation to confirm that TensorFlow is functioning correctly on the CPU.
Upgrade to Python 3.10 or newer. The `tensorflow-cpu` package generally requires Python >=3.10.
Update your code to be compatible with Keras 3. To continue using Keras 2 (tf-keras), install `tf-keras` via `pip install tf-keras~=2.16` and set the environment variable `TF_USE_LEGACY_KERAS=1` before importing TensorFlow.
Migrate your code away from `tf.estimator`. If you must use this API, you will need to use TensorFlow 2.15 or an earlier version.
To explicitly restrict TensorFlow to CPU, add `tf.config.set_visible_devices([], 'GPU')` at the beginning of your script, before any other TensorFlow operations.
Consider adjusting `tf.config.threading.set_intra_op_parallelism_threads()` and `tf.config.threading.set_inter_op_parallelism_threads()`. For Intel CPUs, setting the environment variable `TF_ENABLE_ONEDNN_OPTS=1` can enable oneDNN optimizations (default on Windows x64 & x86 since TF 2.15).
This is a warning, not an error, and TensorFlow will function correctly. To fully leverage your CPU's advanced instructions for potentially better performance, you would need to build TensorFlow from source with specific compiler flags (e.g., -march=native); otherwise, you can safely ignore this warning.
Install the package using pip: `pip install tensorflow-cpu` or ensure you have activated the correct virtual environment where `tensorflow-cpu` is already installed.
Ensure that only `tensorflow-cpu` is installed by explicitly uninstalling any conflicting GPU versions (`pip uninstall tensorflow tensorflow-gpu && pip install tensorflow-cpu`). Also, verify that no lingering environment variables are pointing to non-existent CUDA library paths.
Upgrade pip (`python -m pip install --upgrade pip`), ensure your Python version is officially supported by the specific `tensorflow-cpu` version you're trying to install (e.g., Python 3.9-3.11 for recent TF 2.x versions), and check your internet connection or proxy settings.