This guide covers three ways to use Jupyter Notebooks. Level 0 uses Google Colab, which runs in your browser with no installation needed. For local work, Level 1 uses Anaconda, an easy, all-in-one installation. Level 2 uses Miniconda and VS Code for a more professional and customizable setup, which is highly recommended for long-term project work.
Google Colaboratory, or Colab, is a free, cloud-hosted Jupyter Notebook environment that runs entirely in your web browser.1 It's an excellent starting point, especially for students and beginners, because it requires zero installation or setup on your personal computer.
Key Advantages:
No Setup Required: You can start coding immediately without worrying about installing Python or any libraries. This helps bypass potential setup frustrations.
Free Access to Powerful Hardware: Colab provides free access to powerful hardware like Graphics Processing Units (GPUs) and Tensor Processing Units (TPUs).1 These are specialized processors that can dramatically speed up complex machine learning calculations, a huge benefit if you don't have a high-end computer.
Pre-installed Libraries: Most common data science libraries (like Pandas, NumPy, and Matplotlib) are already installed. You can easily add more using !pip install
in a code cell.
Collaboration and Sharing: Just like Google Docs, you can share your Colab notebooks with a simple link, allowing others to view or edit your work in real-time.
Google Drive Integration: Notebooks are saved to your Google Drive, and you can easily access datasets stored there directly from your notebook.
Getting Started with Colab:
Go to colab.google.com.
Click "New Notebook" to create a new file.
You'll see a "cell." Type Python code into it, like print("Hello from Colab!")
.
Press Shift + Enter to run the code. The output will appear directly below the cell.
Conda is a package and environment manager.6 While it's the tool that powers Anaconda and Miniconda, its most critical feature for any developer is its ability to create
virtual environments.
A virtual environment is an isolated, self-contained directory that holds a specific collection of packages and a specific Python version for a single project.7 Using environments is crucial for avoiding conflicts between projects that may require different versions of the same library.
The Golden Rule:** Don't Work in Your (base) Environment**
When you install Anaconda or Miniconda, it creates a default environment called base. You will see (base) at the start of your terminal prompt. It is a strong best practice to avoid installing project-specific packages directly into the base environment.
Think of the base
environment as the superintendent of an apartment building—its job is to manage the building itself (conda and its core components). Each of your projects should live in its own apartment (a separate conda environment) with its own set of tools and furniture (packages). This keeps your base
clean and ensures your projects are organized, independent, and reproducible.
Essential Conda Commands:
Create a new environment:
conda create --name my-project-env python=3.11
This creates a new, isolated environment named my-project-env with a specific version of Python.
Activate the environment:
conda activate my-project-env
Your terminal prompt will change to (my-project-env), showing you are now inside that environment.
Install packages into the active environment:
conda install pandas jupyterlab
Packages should always be installed into an activated project environment, not base.
See all your environments:
conda env list
This lists all environments you have created. The active one will have an asterisk (*) next to it.
Leave an environment:
conda deactivate
This returns you to the base prompt.
Visual Studio Code (VS Code) is a free, powerful, and highly popular code editor. It can be integrated with your conda environments to create a seamless workflow for writing Python scripts and working with Jupyter Notebooks locally.
Setting Up VS Code with Conda:
Install the Python Extension: Open VS Code, go to the Extensions view (the icon with four squares), search for "Python," and install the official extension from Microsoft.
Open Your Project Folder: Use File > Open Folder..
to open the directory containing your project files.
Select Your Conda Environment: Open the Command Palette with Ctrl+Shift+P
(Windows/Linux) or Cmd+Shift+P
(macOS). Type Python: Select Interpreter
and choose the interpreter associated with the conda environment you created (e.g., Python 3.11 ('my-project-env': conda)
). This tells VS Code to use the Python and packages from that specific environment for your project.
Using Jupyter Notebooks in VS Code:
VS Code has native support for Jupyter Notebooks (.ipynb files), providing a rich user interface for running cells, viewing outputs, and debugging.
Create or Open a Notebook: Create a new file with a .ipynb
extension or open an existing one.
Install the Jupyter Kernel Bridge: For VS Code to "see" your conda environment as a runnable Jupyter kernel, you must install one more package inside that environment. This is a critical and often-missed step.
Open your terminal.
Activate your environment: conda activate my-project-env
Install the ipykernel package: conda install ipykernel
This package acts as a bridge, allowing VS Code's Jupyter interface to communicate with your conda environment.
Select the Kernel: In the top-right corner of the notebook in VS Code, click "Select Kernel." You should now see your conda environment (my-project-env
) in the list. Select it.
Run Code: You can now write code in cells and execute them with Shift + Enter or the "Run" button, just like in Colab. The code will be executed by the Python interpreter and packages from your selected conda environment.
Explore Your Data: VS Code offers powerful tools like a Variable Explorer to inspect dataframes and other objects in memory, and a full-featured debugger for stepping through your code cell by cell.