Conda, Packages, and Jupyter Notebook
Overview¶
By this point, you have already:
✅ Installed Python
✅ Installed Visual Studio Code
✅ Installed the Python extension for Visual Studio Code
✅ Created and ran your first
.pyfile
The next step is learning how to manage Python environments, install packages, and write code in Jupyter Notebooks (.ipynb), which are widely used in data science and neuroscience.
Why Do We Need Environments?¶
As your projects become larger, you’ll begin installing many additional pieces of software.
For example:
NumPy
Pandas
Matplotlib
Scikit-learn
Nilearn
These are called packages (sometimes called libraries).
A package is simply a collection of code written by other programmers that you can reuse instead of writing everything yourself.
For example:
NumPy provides fast numerical arrays and mathematical operations.
Pandas makes it easy to work with tables and spreadsheets.
Matplotlib creates figures and graphs.
Nilearn contains tools for analyzing brain imaging data.
Instead of reinventing the wheel, we simply install these packages and use them in our own programs.
Why Not Install Everything Everywhere?¶
Imagine installing every package you’ve ever needed into one giant Python installation.
Eventually:
different projects may require different package versions,
packages may conflict with one another,
updating one package could accidentally break another project.
To avoid this, we create environments.
An environment is an isolated Python workspace containing:
its own Python installation,
its own packages,
its own dependencies (the software required for packages to work).
Think of an environment as a separate toolbox for each project.
For example, you might eventually have three environments:
neuroimagingeducationquantfinance
Each can have different packages without affecting the others.
The original Python installation is often called the base environment. In general, it is good practice to leave the base environment as clean as possible and create a new environment for each project.
Installing Conda¶
Conda is a tool that creates and manages environments.
Follow the video below from 1:45 onwards to 10:10:
https://
The video covers:
installing Conda,
what environments are,
why environments are useful,
creating environments,
removing environments.
Some terminology may be unfamiliar at first. That’s completely fine. The goal is simply to become familiar with the overall workflow.
The video goes very briefly over installing conda.
For Mac, follow this written guide to install conda:
https://
For Windows, follow this written guide to install conda:
https://
Important (for Windows):
In Step 6 of the written guide, tick “Add Anaconda to my PATH environment variable”, even though the installer says this is not recommended. Tim explains why between 3:03 and 3:39 of the video.
Continue watching the video until approximately 10:10.
You can ignore the sections on:
Visual Studio Code
IntelliSense / Autocomplete
VS Code Extensions
Conda Cheat Sheet¶
The official Conda cheat sheet is a useful reference:
https://
Briefly, have a look. Don’t worry about memorizing every command. We’ll only use a few of them regularly.
Creating Your First Environment¶
Go to your Terminal or Powershell.
The command you’ll probably use most often is:
conda create --name ENVNAME python=3.11Replace ENVNAME with a descriptive name.
For example:
conda create --name neuroimaging python=3.11This creates a new environment called neuroimaging with Python 3.11 installed.
Why specify the Python version?¶
You may notice that the Conda cheat sheet simply shows:
conda create --name ENVNAMEThis creates an empty environment.
Instead, we recommend specifying the Python version so Conda installs Python inside the environment immediately. This allows Visual Studio Code to recognize it as a Python environment.
If you’re unsure which Python version to choose, you can choose Python 3.11 since it is widely supported by many packages.
Activating an Environment¶
Before installing packages, you first need to activate your environment.
conda activate neuroimagingIf the command succeeds, you should see something similar to:
(neuroimaging)at the beginning of your Terminal or PowerShell prompt.
This tells you that any packages you install will be installed inside the neuroimaging environment, rather than into your global (base) Python installation.
Viewing Installed Packages¶
To see which packages are currently installed, type:
conda listYou’ll see many packages already installed.
Don’t worry about understanding them yet.
Most are supporting software that Python requires to run.
Installing Packages¶
Now let’s install two of the most commonly used data science packages.
NumPy¶
NumPy provides fast arrays and numerical computations.
Official installation instructions:
Most packages provide installation instructions in their documentation.
For NumPy, you can install it using either:
conda install numpyor
pip install numpyIf the package provides Conda instructions, we recommend using Conda.
Otherwise, pip install PACKAGENAME usually works well.
Regardless of which method you use, always activate your environment first via your Terminal / Powershell.
Once you run conda install numpy, and when prompted:
Proceed ([y]/n)?simply type:
yand press Enter.
After installation, run:
conda listagain.
You should now see numpy in the list.
Pandas¶
Pandas is a package for working with tabular data (similar to spreadsheets).
Similar to NumPy, we can google their installation instructions. Once you do that, you will hopefully find this link:
https://
You may see instructions such as:
conda install -c conda-forge pandasinstead of the usual:
conda install pandasBoth install Pandas using Conda.
The first explicitly downloads the package from the conda-forge channel, while the second uses your default Conda channels.
You can follow the instructions and type conda install -c conda-forge pandas. If you’re unsure which command to use, feel free to ask ChatGPT to explain the differences.
Using Jupyter Notebook¶
From the previous tutorial, we’ve learned how to write and run Python programs using a .py file. However, data scientists and neuroscientists may prefer using Jupyter Notebooks (.ipynb), which allow you to combine code, figures, and notes in a single document. In fact, we’ll be mostly using Jupyter Notebooks!
Follow the YouTube tutorial on the Visual Studio Code website:
https://
You can follow the tutorial as usual until she reaches Select Kernel → Python Environments (approximately 1:14–1:30).
At this point, do not create a new lightweight environment by typing:
python -m venv ./venvInstead, you should see the Conda environment that you created earlier in this guide. It may look something like:
neuroimaging (Python 3.11.15) /opt/anaconda3/envs/neuroimaging/bin/python(Your exact Python version and file path may be slightly different.)
Select this environment as your Jupyter kernel, then continue following the tutorial from approximately 1:53 onwards.
As you work through the tutorial, focus on learning how to:
create Code cells,
create Markdown cells,
run individual cells.
After watching the video, you may also find the written guide helpful. But don’t worry about remembering every feature of Jupyter Notebook. You’ll become more comfortable with it as you continue writing code.
Testing Your Installation¶
Create a new .ipynb notebook on VS Code and make sure the environment in which you installed numpy and pandas is activated by clicking the Select Kernel.
Create a new Code cell and type:
import numpy as np
import pandas as pdThe import statement tells Python that we’d like to use these packages in our program.
The shorter names:
np
pdare standard abbreviations that you’ll see throughout the scientific Python community.
Run the cell.
If no error messages appear, congratulations!
Both NumPy and Pandas have been installed successfully.
If you receive an error, first check that you’ve selected the correct Jupyter kernel (e.g., your
neuroimagingenvironment). Installing a package into one environment does not automatically make it available in another.