TensorFlow is a powerhouse for machine learning and deep learning. It allows developers to define the flow of data through multidimensional arrays (tensors) to build complex, high-performance neural networks. Before we can build AI models, we need to set up a clean, isolated, and reliable development environment. Follow this step-by-step guide to get TensorFlow running smoothly on your Windows machine using VS Code.
Step 1 & 2: Install Python and VS Code
First, we need the core programming language and a powerful code editor.
Install Python: Download the latest version of Python from python.org.
Crucial Step: During installation, you must check the box that says "Add Python to PATH". This allows your computer to recognize Python commands from anywhere.
Install VS Code: Download and install Visual Studio Code from code.visualstudio.com.
Once installed, open VS Code, go to the Extensions tab (or press
Ctrl+Shift+X), search for "Python" by Microsoft, and install it. This extension provides essential code completion and debugging features.
Step 3: Set Up a Virtual Environment (venv)
A virtual environment acts like a private, isolated workspace for your project. It ensures that the packages you install here won’t conflict with other Python projects on your computer.
Open VS Code and create a new, empty folder for your project. Open this folder in VS Code.
Open the integrated terminal by pressing
Ctrl + `(backtick) or navigating to Terminal > New Terminal.Create the environment by running this command:
python -m venv myenv(This creates a folder named myenv containing your isolated Python setup).
4. Activate the environment:
For PowerShell (default in modern Windows):
.\myenv\Scripts\ActivateSuccess Check: You will know it worked when you see
(myenv)appear at the very beginning of your terminal prompt.
Step 4: Install TensorFlow via PIP
With your virtual environment activated, you are ready to install TensorFlow. pip is Python’s official package manager, used to download and install third-party libraries.
Run the following command in your terminal:
pip install tensorflow(Note: While older tutorials might suggest pip3, the standard pip command is perfectly correct and recommended for modern Python 3.x installations).
Step 5 & 6: Verify Your Installation
Let’s make sure everything is wired up correctly and that TensorFlow can detect your hardware.
In VS Code, create a new file named
test_tf.py.Paste the following code into the file:
import tensorflow as tf
print(" TensorFlow Version:", tf.__version__)
# Check if TensorFlow can utilize your GPU for faster training
gpu_devices = tf.config.list_physical_devices('GPU')
if gpu_devices:
print(" GPU Available: Yes! Hardware acceleration is ready.")
else:
print(" GPU Available: No. Running on CPU (which is perfectly fine for learning!).")Run the script by typing this in your terminal:
python test_tf.pyYou’re Ready! If the terminal prints the TensorFlow version number without throwing any errors, your environment is perfectly configured. You are now ready to start building your first deep learning models!
Creating Tensors
In our above section, we successfully installed TensorFlow and verified that our environment is ready. Now, it’s time to take the first real step: Creating Tensors. As a fresher, you might wonder: "If a Tensor is just an array of numbers, why are there different ways to create one?"
The answer lies in how the data behaves. In the real world, some data is fixed and unchangeable (like a tax rate), while other data is dynamic and constantly flowing in (like new insurance claims). TensorFlow provides specific tools for both scenarios. In this end-to-end guide, we will explore two primary ways to create tensors. To strictly follow the "only use TensorFlow, no other libraries" rule, we will use TensorFlow’s native capabilities to handle array-like data, perfectly mimicking the NumPy approach without needing to import it. Let’s dive into two real-world enterprise scenarios: E-commerce Billing and Insurance Claims Management.
Use Case 1: E-commerce Billing (Creating Tensors via tf.constant)
The Scenario
Imagine you are building an AI pricing engine for a major e-commerce platform. During a checkout session, certain values are fixed and should never change during the calculation. For example, the base price of an item, the fixed shipping fee, or the government-mandated tax rate.
Why tf.constant?
In TensorFlow, tf.constant is used to create immutable tensors. Once created, their values cannot be altered. This is highly optimized for fixed parameters, saving memory and preventing accidental changes during model training or inference.



Join the conversation! Your thoughts help the community grow.