top of page

A Beginner’s Guide to Python Environments

  • Writer: Mayta
    Mayta
  • 7 hours ago
  • 3 min read

Introduction

A Beginner’s Guide to Python Environments

A clean, practical introduction for new programmers, researchers, and CECS students

Managing Python environments is one of the most important early skills for anyone entering programming, data science, or clinical statistics. Many beginners underestimate this topic—until they face problems such as:

  • “ModuleNotFoundError: package not found”

  • “This function works on my laptop but not on the lab computer.”

  • “Upgrading pandas broke my older scripts!”

A proper environment setup saves hours of debugging and keeps projects reproducible and clean.

What Exactly Is a Python Environment?

Think of a Python environment like a special room designed for a specific task:

  • When you want to cook, you create a room with cooking tools and call it a kitchen.

  • When it's time to cook, you must go into the kitchen, not the bedroom.

  • The kitchen has its own tools, and using the wrong room means you can’t cook properly.

A Python environment works the same way:

  • You prepare a “room” and install the packages you need for a project.

  • Everything stays inside that environment.

  • If you run your code from the wrong environment, it may fail because the tools aren’t there.

This avoids conflicts between projects. For example:

Project

Python Version

pandas Version

numpy Version

COVID risk model

3.12

2.1

1.26

Hospital LOS prediction

3.9

1.5

1.20

Each project remains isolated.

Miniconda vs. Anaconda

Both use the Conda package/environment manager, but they differ in how much they install up front.

Miniconda (Recommended)

  • Lightweight

  • Ships only Python + Conda

  • You install only what you need

  • Faster, cleaner, ideal for CECS, research, and production work

Anaconda Distribution

  • Heavy (thousands of packages pre-installed)

  • Useful for beginners in data science

  • Larger downloads and slower environments

Best for serious learners and researchers: Miniconda.

Why Environments Matter

If you install everything inside the global base environment:

  • Packages conflict rapidly

  • Updating one breaks another

  • Debugging becomes painful

  • Reproducibility becomes impossible

Separate environments ensure:

✔ Clean versions ✔ Conflict-free installations

✔ True reproducibility ✔ Stable clinical-statistical pipelines (critical in CECS research)

This parallels CECS principles: keep analysis datasets isolated, avoid contamination, and maintain reproducibility .

How Conda Environments Work

Here’s what your commands actually did, explained.

✔ Listing installed packages

conda list

Shows what is installed in the current environment.

✔ Creating a new environment

conda create -n test_env python=3.13

This creates a fresh environment named test2_env with its own Python 3.13 interpreter.

✔ Activating the environment

conda activate test_env

Your terminal prefix changes to (test_env) → meaning you are now inside that environment.

✔ Installing packages inside the environment

pip install pandas

Since you're inside test_env, pandas is installed only there — not system-wide.

This isolation principle is similar to CECS analysis logic where each model class (logistic, Cox, Poisson) is fitted according to the specific data structure and assumptions, avoiding contamination from unrelated settings .

How to Use Conda Environments in IDEs

Most beginners forget this step!

✔ Visual Studio Code (VS Code)

  1. Press Ctrl + Shift + P

  2. Search Python: Select Interpreter

  3. Choose your conda environment path:

    .../.conda/envs/test_env/python.exe

✔ PyCharm

  1. File → Settings → Project → Interpreter

  2. Add Interpreter → Conda

  3. Select Existing environment: test_env

✔ Jupyter Notebook / JupyterLab

Install a Jupyter kernel associated with the environment:

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

You will then be able to choose the kernel inside Jupyter.

Essential Conda Commands (Beginner Cheat Sheet)

Create environment

conda create -n my_env python=3.12

Activate / deactivate

conda activate my_env
conda deactivate

List environments

conda env list

Install packages

conda install numpy
pip install numpy

Remove a package

conda remove numpy

Delete an environment

conda remove -n my_env --all


How Python Environments Support CECS Workflows

Although environments are a programming concept, they directly support the CECS statistical workflow:

✔ Reproducibility

Survival analysis, prediction modeling, and causal inference must run identically across machines and dates. Environment isolation prevents version drift—critical for clinical reproducibility and model validation.

✔ Compatibility

Different analyses require different versions of packages:

  • lifelines or scikit-survival for Cox models

  • statsmodels for logistic/Poisson/GLM

  • scikit-learn for clinical prediction modeling (discrimination, calibration)

Separate environments let each project choose the right set of tools.

✔ Clean Model Development

Just like CECS modeling strategies avoid mixing explanatory, exploratory, and predictive frameworks , software environments should also remain cleanly separated.

Recent Posts

See All
Effect Size, MCID/CID, and Sample Size Relevance

1. Effect Size: The Foundation of Clinical Interpretation Effect size (ES) is the magnitude of difference or association  between groups, exposures, treatments, or predictors. It is the central compo

 
 
 
Post: Blog2_Post

​Message for International and Thai Readers Understanding My Medical Context in Thailand

Message for International and Thai Readers Understanding My Broader Content Beyond Medicine

bottom of page