Abhigyan Chakraborty

Managing Projects with Conda Environments

Phase 1: The Local Workbench — Part 3

(Part 3 of series Blueprint for a Modern Research Computing Environment)

Follow me :

LinkedIn    Website    Website


Quick Summary

This article creates an isolated Conda environment (env_project1), installs numpy through it, and explains when to use conda install vs pip install. You’ll then run the same piece of Python code two ways — as a .py script and inside a JupyterLab .ipynb notebook — to see how the two workflows differ.


Objective

In Part 2, we created ~/project_1 — a folder for our first project. But a folder alone is not enough. Every Python project also needs its own environment — a controlled space where you install only the packages that project needs.

In this article, we’ll create that environment, install packages, and run our first Python code in both a .py and .ipynb file.

By the end, you’ll have:


Content

💡 Getting Unstuck (Expand for AI Troubleshooting Prompts)

AI tools (like Claude, Grok, Gemini, or ChatGPT) give the best troubleshooting advice when they have the exact text of the tutorial. To ensure the AI understands what you are trying to build, we will give it the actual file.

1. Download the tutorial file

2. Upload it to your AI

3. Ask for Help Copy and paste this exact prompt into the chat along with your file:

I have attached the markdown file for the tutorial I am following. Please read it so you understand the specific environment I am trying to build.

I need help with the following:

Step [X]: [paste exact step text from the blog]

Command I ran: [paste exact command]

What happened: [paste full output/error — if the terminal was truly blank, say so explicitly]

Please help me troubleshoot and fix this error. You can use your general knowledge to solve the problem, but your solution MUST align with the architecture and tools taught in the attached file. Do not suggest alternative setups that contradict the tutorial. Once fixed, tell me what to do next in the article.

To go deeper on a step before you run a command:

I have attached the Part3.md file. Look at Step [X] and explain exactly what the command does and why we are doing it before I run it.

Think of this series as the roadmap and your AI assistant as your learning companion.

Prerequisites

Step 1 — What Are Python Packages?

Python by itself is minimal. Packages are collections of code written by others that you can use in your own projects.

For example:

Instead of writing everything from scratch, you install a package and use it.

Step 2 — Why Virtual Environments?

Imagine two projects:

If you install both on the same Python, they conflict. Virtual environments solve this — each project gets its own isolated Python with its own packages and versions.

With Miniconda, these are called Conda environments.

Step 3 — Create a Conda Environment

Navigate to your project folder:

cd ~/project_1

Create an environment named env_project1 with Python 3.11:

conda create -n env_project1 python=3.11 pip

Note: Always include pip explicitly when creating an environment. Unlike the defaults channel, conda-forge doesn’t bundle pip automatically with Python — skip it, and later pip install commands will fail with errors like pip3: command not found or No module named pip.

Conda will show a list of packages to install. Type y and press Enter.

Activate the environment:

conda activate env_project1

Your prompt will change from (base) to (env_project1):

(env_project1) abhigyan@DESKTOP-XXXX:~/project_1$

This means you are now inside your isolated environment. Any package you install from this point goes into env_project1 only — not into any other environment.

Step 4 — Managing Your Environments

Before we install anything, a few commands worth knowing now that you have your first environment.

List all environments:

conda env list

Output:

# conda environments:
#
base                  *  ~/miniconda3
env_project1             ~/miniconda3/envs/env_project1

The * shows your currently active environment.

Where environments are stored:

Each environment lives inside ~/miniconda3/envs/. You never need to go there directly — Conda manages it for you. But knowing this helps when you’re wondering where your packages actually live.

Deactivate an environment:

conda deactivate

Switches you back to (base). Always deactivate before deleting an environment.

Delete an environment:

conda env remove -n env_project1

This permanently deletes the environment and all packages inside it. Don’t run this now — we’ll need env_project1 for the rest of the series.

Step 5 — Installing Packages (also called Libraries)

Make sure env_project1 is active before installing anything:

conda activate env_project1

conda install vs pip install

There are two ways to install packages:

  conda install pip install
Source Conda repositories Python Package Index (PyPI)
Handles non-Python dependencies Yes No
Environment safety Better Can break Conda environments if overused
When to use Default choice When package is not available via Conda

Rule of thumb: always try conda install first. Use pip install only if the package is not available through Conda.

The conda-forge Channel

Conda packages are hosted in channels — think of them as app stores. The default Conda channel has many packages, but conda-forge is a community-maintained channel with significantly more packages and more up-to-date versions.

Set conda-forge as your default channel:

conda config --add channels conda-forge
conda config --set channel_priority strict

You only need to do this once — it applies to all environments.

Install numpy

NumPy is a Python package that provides support for arrays and mathematical operations. It is one of the core libraries used in data science and scientific computing.

conda install numpy

Type y when prompted.

Verify the installation:

python -c "import numpy; print(numpy.__version__)"

You should see a version number printed.

Step 6 — Two Ways to Write Python: .py and .ipynb

Before writing any code, it helps to understand the two file types you’ll use throughout this series.

.py — Python Script

A plain text file containing Python code. You run it from the terminal and it executes top to bottom.

Best for:

.ipynb — Jupyter Notebook

A notebook file where code, output, and text live together in cells. You run cells one at a time and see the output immediately below each cell.

Best for:

Both are valid. Most research workflows use both — notebooks for exploration, scripts for automation.

Step 7 — Run Your First .py Script

Make sure you are in ~/project_1 with env_project1 active.

Create a file:

touch first_script.py

Open it in a terminal text editor. We’ll use nano — a simple terminal text editor — to write our script directly in the terminal. (More about nano in Part 5).

nano first_script.py

Type this code:

import numpy as np

a = np.array([1, 2, 3, 4, 5])
print("Array:", a)
print("Mean:", np.mean(a))
print("Sum:", np.sum(a))

Save and exit: press Ctrl+X, then Y, then Enter.

Run the script:

python first_script.py

Expected output:

Array: [1 2 3 4 5]
Mean: 3.0
Sum: 15

Step 8 — What is Jupyter Notebook and JupyterLab?

Jupyter Notebook is the original browser-based interface for .ipynb files. You write code in cells, run them one at a time, and see output immediately below.

JupyterLab is the modern replacement. It has the same notebook functionality but adds a file browser, terminal, text editor, and multiple tabs — all in one browser window.

For this series, we use JupyterLab.

Step 9 — Install JupyterLab and ipykernel

ipykernel is what connects your Conda environment to JupyterLab. Without it, JupyterLab won’t see env_project1 as an available kernel.

Install both:

conda install jupyterlab ipykernel

Type y when prompted.

Register your environment as a Jupyter kernel:

python -m ipykernel install --user --name env_project1 --display-name "Python (env_project1)"

Step 10 — Run Your First .ipynb Notebook

Launch JupyterLab:

jupyter lab

JupyterLab will open in your browser automatically. If it doesn’t, copy the URL from the terminal — it will look like:

http://localhost:8888/lab?token= ...... copy the entire line

and paste it into your browser.

In JupyterLab:

  1. Click File → New → Notebook
  2. Select Python (env_project1) as the kernel
  3. In the first cell, type:
import numpy as np

a = np.array([1, 2, 3, 4, 5])
print("Array:", a)
print("Mean:", np.mean(a))
print("Sum:", np.sum(a))
  1. Press Shift+Enter to run the cell

Expected output:

Array: [1 2 3 4 5]
Mean: 3.0
Sum: 15

Same result as the .py script — but this time inside a notebook cell, with output directly below your code.

To stop JupyterLab, go back to the terminal and press Ctrl+C.

Step 11 — Why Use an IDE Like VS Code?

JupyterLab is a capable environment. For notebooks and interactive work, it works well on its own.

But as your projects grow, you’ll find yourself needing more:

JupyterLab is purpose-built for notebooks and interactive computing — and it does that extremely well. An IDE like VS Code goes further by bringing your entire development workflow — code, terminal, Git, debugger, and notebooks — into a single environment. As your projects grow in complexity, having everything in one place makes a real difference.

In Part 4, we’ll set up VS Code and connect it to the environment we built here.


What’s Next

What You’ve Done:

Next: Part 4 — Setting Up VS Code | Previous: Part 2 — Terminal Basics and File Navigation

All Blogs