Updated: Jul 12, 2026
| 14 min

Python Data Science Setup: VS Code, venv, Jupyter and Colab

Set up Python for data science using VS Code, a virtual environment, Jupyter notebooks, essential libraries, and Google Colab.

Banner for "Data Science with Python" showing a snake and data analysis tools

Before writing Python code or analysing datasets, you need a reliable environment in which to run your projects.

In this chapter, you will learn how to set up Python for data science using two popular workflows:

  • A local Python environment with VS Code, venv, and Jupyter Notebook
  • A cloud-based environment with Google Colab

A local environment gives you greater control over your files, packages, and project structure. Google Colab provides a faster way to begin experimenting without installing software on your computer.

By the end of this tutorial, you will be able to create and activate a Python virtual environment, install essential data science libraries, run Jupyter notebooks in VS Code, and work with notebooks in Google Colab.

What You Will Install

For the local data science environment, you will use:

  • Python to run your code
  • Visual Studio Code as your code editor
  • venv to create an isolated Python environment
  • Jupyter Notebook for interactive analysis
  • NumPy, pandas, Matplotlib, Seaborn, SciPy, and scikit-learn for data analysis, visualisation, scientific computing, and machine learning

The cloud environment uses Google Colab, which runs Python notebooks inside a browser.

VS Code vs Google Colab for Data Science

VS Code and Google Colab can both run Jupyter notebooks, but they are suited to different workflows.

FeatureVS CodeGoogle Colab
Installation requiredYesNo
Runs locallyYesNo, unless connected to a local runtime
Package controlFull controlPackages may need reinstalling after a runtime reset
File storageYour computerGoogle Drive and temporary runtime storage
Offline useYesUsually requires an internet connection
GPU or TPU accessRequires compatible local hardwareOptional access, subject to availability and usage limits
Best suited forLong-term projects and developmentLearning, experimentation, and sharing notebooks

For this course, either environment will work. However, learning how to use a local virtual environment is an important part of building reproducible Python projects.

How to Set Up Python for Data Science in VS Code

The following steps create a complete local Python data science environment.

Step 1: Install Python

Download Python from the official website:

Download Python

Choose a recent stable version of Python 3 that is supported by the libraries you plan to use.

Windows Installation

When using the standard Windows installer, enable the option:

Add Python to PATH

This allows you to run Python commands from PowerShell, Command Prompt, and the VS Code terminal.

After installation, open a terminal and check the installed version:

python --version

If the python command is not recognised on Windows, try the Python launcher:

py --version

macOS or Linux Installation

On macOS and Linux, the Python 3 command may be named python3:

python3 --version

The terminal should return a version number similar to:

Python 3.x.x

Step 2: Install Visual Studio Code

Download and install Visual Studio Code from the official website:

Download Visual Studio Code

After opening VS Code, select the Extensions icon in the Activity Bar or use the following shortcut:

Ctrl + Shift + X

Install these two extensions:

  1. Python
    • Extension ID: ms-python.python
  2. Jupyter
    • Extension ID: ms-toolsai.jupyter

The Python extension provides Python language support, interpreter selection, debugging, and environment management.

The Jupyter extension allows you to create and run .ipynb notebooks directly inside VS Code.

Step 3: Create a Data Science Project Folder

Create a separate folder for your first project. For example:

my-first-data-science-project

Open the folder in VS Code:

  1. Select File → Open Folder
  2. Choose your project folder
  3. Confirm that you trust the folder when VS Code displays the Workspace Trust prompt

Keeping each project inside its own folder makes it easier to manage notebooks, datasets, dependencies, and other project files.

A basic project may eventually look like this:

my-first-data-science-project/
├── .venv/
├── data/
├── notebooks/
├── analysis.ipynb
├── requirements.txt
└── .gitignore

You do not need to create every file and folder immediately. This structure simply provides room for the project to grow.

Step 4: Open the VS Code Terminal

Open the integrated terminal by selecting:

Terminal → New Terminal

You can also use the standard terminal shortcut:

Ctrl + `

The backtick key is normally located below the Escape key.

Make sure the terminal is currently located inside your project folder before continuing.

Step 5: Create a Python Virtual Environment

A Python virtual environment creates an isolated location for your project’s packages.

This prevents packages installed for one project from interfering with packages used by another project.

The conventional name for a project-level virtual environment is .venv.

Windows

Run:

py -m venv .venv

You can use the following command instead when python is available:

python -m venv .venv

macOS or Linux

Run:

python3 -m venv .venv

After the command finishes, a .venv directory will appear inside the project folder.

Do not manually edit files inside this directory.

Step 6: Activate the Virtual Environment

The activation command depends on your operating system and terminal.

Windows PowerShell

.venv\Scripts\Activate.ps1

Windows Command Prompt

.venv\Scripts\activate.bat

macOS or Linux

source .venv/bin/activate

After activation, your terminal prompt should begin with something similar to:

(.venv)

This indicates that commands such as python and pip are now using the project’s isolated environment.

PowerShell Execution Policy Error

Windows PowerShell may prevent the activation script from running.

When PowerShell reports that script execution is disabled, run the following command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Close and reopen the terminal before attempting to activate the environment again.

This changes the execution policy only for your Windows user account.

Step 7: Upgrade pip

Before installing the data science packages, update pip inside the active virtual environment:

python -m pip install --upgrade pip

Using python -m pip helps ensure that packages are installed through the Python interpreter belonging to the active environment.

Step 8: Install the Essential Data Science Libraries

With the virtual environment active, install the core libraries:

python -m pip install numpy pandas matplotlib seaborn scipy scikit-learn jupyter ipykernel

The packages serve different purposes:

  • NumPy provides fast numerical calculations and multidimensional arrays.
  • pandas provides DataFrames and tools for cleaning, transforming, and analysing structured data.
  • Matplotlib creates charts and other data visualisations.
  • Seaborn provides a higher-level interface for statistical visualisations built on Matplotlib.
  • SciPy provides tools for scientific computing, statistics, optimisation, signal processing, and linear algebra.
  • scikit-learn provides machine-learning algorithms and data-preprocessing tools.
  • Jupyter provides the notebook environment.
  • ipykernel allows the virtual environment to run as a Jupyter kernel.

These libraries provide a strong foundation for most beginner and intermediate data science projects.

Step 9: Select the Python Interpreter in VS Code

VS Code may discover the .venv environment automatically. You should still confirm that the correct interpreter is selected.

  1. Press Ctrl + Shift + P to open the Command Palette.
  2. Search for:
Python: Select Interpreter
  1. Select the interpreter associated with .venv.

It may appear as:

Python 3.x.x ('.venv': venv)

You may also be able to select the interpreter by clicking the Python version displayed in the VS Code status bar.

Selecting the correct interpreter ensures that Python files and related development tools use the packages installed inside your virtual environment.

Step 10: Create a Jupyter Notebook in VS Code

You can create a notebook through the Command Palette or by creating an .ipynb file manually.

Method 1: Use the Command Palette

  1. Press Ctrl + Shift + P.
  2. Search for:
Create: New Jupyter Notebook
  1. Select the command.
  2. Save the notebook as:
analysis.ipynb

Method 2: Create the File Manually

  1. Select the New File icon in the Explorer.
  2. Enter:
analysis.ipynb
  1. Press Enter.

VS Code recognises the .ipynb extension and opens the file in the Notebook Editor.

Inside the notebook, you can:

  • Add Python cells with + Code
  • Add explanatory text with + Markdown
  • Run a cell with the play button
  • Run a cell and move to the next one with Shift + Enter
  • View charts directly below the code that produced them

Jupyter notebooks are particularly useful for exploring datasets, documenting an analysis, testing ideas, and creating visualisations.

Step 11: Connect the Notebook to the Virtual Environment

Creating a virtual environment does not automatically guarantee that every notebook is using it.

You must select the .venv environment as the notebook kernel.

  1. Open analysis.ipynb.
  2. Select Select Kernel in the top-right corner of the Notebook Editor.
  3. Select Python Environments when that option is displayed.
  4. Choose the Python interpreter associated with .venv.

The selected kernel should resemble:

Python 3.x.x (.venv)

The notebook can now access the packages installed in the virtual environment.

Using the wrong kernel is one of the most common causes of this error:

ModuleNotFoundError

When a package is installed but cannot be imported, check the selected notebook kernel before reinstalling anything.

Step 12: Test the Data Science Environment

Create a code cell and run the following Python code:

import numpy as np
import pandas as pd
import matplotlib
import seaborn as sns
import scipy
import sklearn

print("NumPy:", np.__version__)
print("pandas:", pd.__version__)
print("Matplotlib:", matplotlib.__version__)
print("Seaborn:", sns.__version__)
print("SciPy:", scipy.__version__)
print("scikit-learn:", sklearn.__version__)
print("The data science environment is ready.")

If the code runs without errors, your environment and notebook kernel are configured correctly.

You can also test a simple pandas DataFrame:

import pandas as pd

data = {
    "city": ["Amsterdam", "Berlin", "Madrid"],
    "temperature": [18, 21, 27]
}

df = pd.DataFrame(data)
df

The notebook should display the DataFrame as a formatted table.

Step 13: Save the Project Dependencies

A dependency file records the packages installed in your project environment.

Create a requirements.txt file by running:

python -m pip freeze > requirements.txt

The file will contain package names and versions, for example:

numpy==x.x.x
pandas==x.x.x
scikit-learn==x.x.x

Another developer can recreate the environment by creating a new virtual environment and running:

python -m pip install -r requirements.txt

A requirements file improves reproducibility and makes it easier to move a project between computers.

Step 14: Add a .gitignore File

Virtual environment files should not normally be uploaded to Git repositories.

Create a file named .gitignore in the project folder and add:

.venv/
__pycache__/
.ipynb_checkpoints/
.env

The important project dependencies are already recorded in requirements.txt, so there is no need to commit the entire .venv directory.

How to Deactivate a Python Virtual Environment

When you have finished working, deactivate the virtual environment by running:

deactivate

The command is the same on Windows, macOS, and Linux.

The (.venv) prefix should disappear from the terminal prompt.

You can activate the environment again the next time you open the project.

How to Set Up Google Colab for Data Science

Google Colab is a browser-based notebook environment. It allows you to write and run Python without installing Python, VS Code, or Jupyter on your computer.

Open the official Colab website:

Open Google Colab

Sign in with a Google account and create a new notebook.

Colab notebooks use the same .ipynb format as Jupyter notebooks, making it possible to move notebooks between Colab and VS Code.

Create a New Google Colab Notebook

From the Colab home screen:

  1. Select New notebook.
  2. Click the notebook name in the top-left corner.
  3. Rename it to something descriptive, such as:
first_data_science_analysis.ipynb

Colab notebooks are stored in Google Drive when they are saved through your Google account.

You can organise them into project folders in Drive just like other files.

Run Python Code in Google Colab

Enter the following code in the first cell:

print("Google Colab is ready.")

Run the cell using the play button or press:

Shift + Enter

Colab connects to a hosted runtime and executes the Python code in the cloud.

Check the Installed Packages in Colab

Many commonly used data science libraries are already available.

Test the core packages with:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn

print("NumPy:", np.__version__)
print("pandas:", pd.__version__)
print("scikit-learn:", sklearn.__version__)

Because Colab updates its runtime environment periodically, the installed versions may differ from those in your local project.

Install Additional Packages in Colab

When a required package is missing, install it from a notebook cell using %pip:

%pip install package-name

For example:

%pip install openpyxl

You can also request a particular version:

%pip install openpyxl==3.1.5

Packages installed inside a Colab runtime are temporary. You may need to reinstall them after the runtime is disconnected, deleted, or reset.

For reproducible notebooks, place required installation commands near the beginning of the notebook.

Access Files from Google Drive

A Colab notebook can mount your Google Drive so that Python code can read and write files stored there.

Run:

from google.colab import drive

drive.mount("/content/drive")

Colab will ask you to authorise access.

After mounting Drive, files are usually accessible under:

/content/drive/MyDrive/

For example, you can load a CSV file with pandas:

import pandas as pd

file_path = "/content/drive/MyDrive/data/example.csv"
df = pd.read_csv(file_path)

df.head()

Only mount Google Drive in notebooks you trust. Code running in a mounted notebook may be able to access files stored in your Drive.

Upload a Local File to Colab

For a temporary upload, use:

from google.colab import files

uploaded = files.upload()

A file-selection window will open.

Uploaded files are stored in the current runtime rather than permanently in Google Drive. They will be removed when the runtime is deleted.

Use a GPU or TPU in Google Colab

Colab may provide optional access to accelerated hardware.

To change the runtime:

  1. Open the Runtime menu.
  2. Select Change runtime type.
  3. Choose a hardware accelerator when available.
  4. Save the setting.

Possible options may include:

  • CPU
  • GPU
  • TPU

Accelerated hardware is not required for normal pandas analysis, basic visualisation, or most beginner exercises.

GPU and TPU availability is not guaranteed. Free and paid Colab accounts are subject to changing availability, usage limits, idle timeouts, and runtime limits.

Use a standard CPU runtime unless your code can benefit from accelerated hardware.

Important Differences Between Colab and a Local Environment

A Colab notebook is saved, but the machine running its code is temporary.

This means that the following may disappear when the runtime ends:

  • Installed packages
  • Uploaded files
  • Variables stored in memory
  • Generated files that were not copied to Google Drive
  • The current execution state

The notebook’s code, Markdown cells, and saved output remain available, but you may need to rerun the notebook from the beginning during a new session.

A local VS Code project provides more persistent control over packages, environments, and files.

Use Google Colab when you want to:

  • Start coding immediately
  • Follow a tutorial without installing software
  • Share a notebook with another person
  • Experiment with optional cloud hardware
  • Work from different computers

Use VS Code with a virtual environment when you want to:

  • Build a long-term project
  • Control package versions
  • Work with several scripts and notebooks
  • Use Git and GitHub
  • Work offline
  • Organise larger datasets and project files
  • Develop reusable Python modules

Learning both workflows gives you the flexibility to choose the best environment for each data science project.

Common Setup Problems

Python Is Not Recognised in the Terminal

Try the alternative command for your operating system:

py --version

or:

python3 --version

On Windows, you may need to reinstall Python and enable the option that adds Python to your PATH.

The Virtual Environment Does Not Appear in VS Code

Try the following:

  1. Confirm that .venv exists inside the open project folder.
  2. Open the Command Palette.
  3. Run Python: Select Interpreter.
  4. Select the .venv interpreter manually.
  5. Reload the VS Code window when necessary.

You can reload VS Code by opening the Command Palette and selecting:

Developer: Reload Window

The Notebook Reports ModuleNotFoundError

This normally means that the notebook is using a different Python kernel from the environment where the package was installed.

Check the kernel name in the top-right corner of the notebook and select .venv.

You can inspect the Python executable used by the notebook with:

import sys

print(sys.executable)

The displayed path should point to the .venv directory.

pip Installs a Package in the Wrong Environment

Activate the virtual environment and use:

python -m pip install package-name

You can verify the active Python interpreter with:

python -c "import sys; print(sys.executable)"

PowerShell Blocks the Activation Script

Run:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Then restart the VS Code terminal and activate .venv again.

Colab Loses Installed Packages

Colab runs notebooks inside temporary virtual machines.

Add installation commands near the top of the notebook so the environment can be restored when a new runtime starts:

%pip install package-name

Frequently Asked Questions

Do I Need Anaconda for Data Science?

No. You can create a complete data science environment using Python’s built-in venv module and pip.

Anaconda can be useful for managing scientific packages and Conda environments, but it is not required for this course or for most beginner projects.

Why Should I Use a Python Virtual Environment?

A virtual environment keeps project dependencies separate.

For example, one project can use one version of pandas while another project uses a different version without causing a conflict.

Should I Name the Environment venv or .venv?

Both names work.

The name .venv is commonly used for an environment stored inside a project folder. The leading dot also makes the directory less visually prominent on operating systems that hide dot-prefixed files.

Do I Need to Install Jupyter Separately?

For notebooks in VS Code, install the VS Code Jupyter extension and the required Python packages inside your environment:

python -m pip install jupyter ipykernel

The extension provides notebook support in the editor, while the Python packages allow the selected environment to run notebook code.

Why Is My VS Code Notebook Using the Wrong Python Version?

The selected notebook kernel may differ from the Python interpreter selected for regular .py files.

Open the kernel selector in the top-right corner of the notebook and choose the .venv environment.

Are Packages Permanently Installed in Google Colab?

No. Packages installed with %pip belong to the current temporary runtime.

The notebook remains saved, but packages may need to be installed again when a new runtime is created.

Is Google Colab Free?

Colab provides a free access tier, but resources are not guaranteed or unlimited.

Hardware availability, runtime duration, idle timeouts, and usage limits may change. Paid plans provide additional compute access but can still be subject to availability and account limits.

Should I Use VS Code or Google Colab?

Use Google Colab for quick experiments, browser-based learning, and easily shared notebooks.

Use VS Code for larger or long-term projects that require persistent files, controlled dependencies, Git integration, and a structured development workflow.

Next Steps

Your Python data science environment is now ready.

You have learned how to:

  • Install Python and VS Code
  • Create and activate a Python virtual environment
  • Install the essential data science libraries
  • Create a Jupyter notebook in VS Code
  • Connect the notebook to the correct kernel
  • Record project dependencies
  • Run Python notebooks in Google Colab
  • Access files stored in Google Drive
  • Choose between a local and cloud-based workflow

In the next chapter, you can begin working with Python fundamentals and the core tools used to explore, clean, analyse, and visualise data.

Series: Data Science with Python

3 Chapters