How to Set Up Visual Studio Code for Machine Learning and Deep Learning: A Step-by-Step Beginner’s Guide

Visual Studio Code setup workflow for Python, Jupyter, machine learning, and deep learning beginners

Visual Studio Code is a flexible development environment for Python, machine learning, and deep learning projects.

Unlike a browser-based notebook environment, Visual Studio Code runs on your computer and gives you more control over project files, Python environments, packages, notebooks, and source code.

In this guide, we will set up Visual Studio Code for AI development and run one simple machine-learning example and one deep-learning example.

What You Will Set Up

By the end of this guide, you will have:

Visual Studio Code → Python → Jupyter → Libraries → Machine Learning → Deep Learning

You will also understand how the main pieces work together.

Step 1: Install Visual Studio Code

Download and install Visual Studio Code on your computer.

Visual Studio Code is the editor, but it does not include Python itself. You also need a Python interpreter installed separately.

Step 2: Install Python

Install a currently supported version of Python.

After installation, open a terminal and check that Python is available:

python --version

Depending on your operating system, you may need:

python3 --version

If a Python version appears, the interpreter is available.

Step 3: Install the Python Extension

Open Visual Studio Code.

Select Extensions from the left sidebar and search for:

Python

Install the official Microsoft Python extension.

The extension adds features such as code completion, debugging, interpreter selection, and Python environment support. Microsoft also documents support for switching between environments directly in VS Code.

Step 4: Install the Jupyter Extension

From the Extensions panel, search for:

Jupyter

Install the Microsoft Jupyter extension.

This allows Visual Studio Code to open and run .ipynb notebooks with executable code cells, Markdown cells, outputs, variables, and debugging support.

Step 5: Create a Project Folder

Create a folder such as:

AI_Project

Open it in Visual Studio Code using:

File → Open Folder

Keeping each project in its own folder makes files and environments easier to manage.

Step 6: Create a Virtual Environment

Open the Visual Studio Code terminal and run:

python -m venv .venv

On Windows, activate it with:

.venv\Scripts\activate

On macOS or Linux:

source .venv/bin/activate

A virtual environment keeps the project's Python packages separate from other projects.

Step 7: Install the Required Libraries

Install the libraries used in our examples:

pip install numpy scikit-learn matplotlib tensorflow jupyter

The exact packages required will depend on your project.

Step 8: Select the Python Interpreter

In Visual Studio Code, open the Command Palette:

Ctrl + Shift + P

Search for:

Python: Select Interpreter

Choose the interpreter from the .venv environment.

For Jupyter notebooks, also select the appropriate kernel from the kernel selector at the top-right of the notebook. This is the workflow recommended in Microsoft's Jupyter documentation.

Step 9: Create a Jupyter Notebook

Create a new file:

AI_Guide.ipynb

Add a code cell and test Python:

print("AI environment is ready!")

Run the cell.

If the message appears, your notebook environment is working.

Step 10: Run a Simple Machine-Learning Example

We can use the Iris dataset and a k-Nearest Neighbours classifier.

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load the dataset
X, y = load_iris(return_X_y=True)

# Split into training and testing data
X_train, X_test, y_train, y_test = train_test_split(
    X,
    y,
    test_size=0.2,
    random_state=42,
    stratify=y
)

# Create the model
model = KNeighborsClassifier(n_neighbors=3)

# Train the model
model.fit(X_train, y_train)

# Evaluate it
accuracy = model.score(X_test, y_test)

print("Accuracy:", accuracy)

train_test_split() separates data into training and testing subsets, while KNeighborsClassifier predicts a class using nearby training examples.

The workflow is:

Data → Split → Model → Training → Evaluation

Step 11: Run a Simple Deep-Learning Example

Now use TensorFlow/Keras with the MNIST handwritten-digit dataset.

import tensorflow as tf

# Load MNIST
(x_train, y_train), (x_test, y_test) = (
    tf.keras.datasets.mnist.load_data()
)

# Scale pixel values
x_train = x_train / 255.0
x_test = x_test / 255.0

# Build a simple neural network
model = tf.keras.Sequential([
    tf.keras.Input(shape=(28, 28)),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(64, activation="relu"),
    tf.keras.layers.Dense(10, activation="softmax")
])

# Configure the model
model.compile(
    optimizer="adam",
    loss="sparse_categorical_crossentropy",
    metrics=["accuracy"]
)

# Train
model.fit(x_train, y_train, epochs=3)

# Evaluate
model.evaluate(x_test, y_test)

TensorFlow's beginner workflow follows the same main stages: load data, build a neural network, train it, and evaluate its accuracy.

Common Problems

If a library cannot be imported, confirm that it was installed into the same Python environment selected by Visual Studio Code.

If a notebook does not run, verify the selected Jupyter kernel.

If TensorFlow installation fails, check that your Python and TensorFlow versions are compatible before changing your entire project environment.

Visual Studio Code or Google Colab?

Visual Studio Code is useful when you want:

  • Local project files
  • More control over Python environments
  • Git and source control
  • Debugging
  • Larger software projects
  • A development environment you can customise

Google Colab may be easier when you want to start quickly without installing a local environment.

Final Thoughts

Visual Studio Code provides a practical environment for progressing from simple Python notebooks to larger machine-learning and deep-learning projects.

The most important setup is straightforward:

Install VS Code → Install Python → Add Python and Jupyter extensions → Select an environment → Install libraries → Run your model

Once this environment works, you can reuse the same workflow for datasets, machine-learning models, neural networks, and more advanced AI projects.

Wise up to AI. Learn it. Use it. Grow with it.

References and Further Reading

Microsoft (n.d.) Python in Visual Studio Code. Visual Studio Code Documentation. Available at: Microsoft – Python in Visual Studio Code documentation (Accessed: 16 September 2026).

Microsoft (n.d.) Jupyter Notebooks in VS Code. Visual Studio Code Documentation. Available at: Microsoft – Jupyter Notebooks in Visual Studio Code documentation (Accessed: 16 September 2026).

Scikit-learn Developers (n.d.) train_test_split. Scikit-learn Documentation. Available at: Scikit-learn – train_test_split documentation (Accessed: 16 September 2026).

Scikit-learn Developers (n.d.) KNeighborsClassifier. Scikit-learn Documentation. Available at: Scikit-learn – KNeighborsClassifier documentation (Accessed: 16 September 2026).

TensorFlow (2024) TensorFlow 2 Quickstart for Beginners. TensorFlow Core. Available at: TensorFlow – TensorFlow 2 Quickstart for Beginners (Accessed: 16 September 2026).