Environments, Packages and Jupyter

Isolated environments, dependency management and working productively in notebooks without creating an unreproducible mess.

Beginner · about 5 hours · difficulty 1/5

Learn first: Python for Machine Learning

ML projects depend on many fast-moving libraries (NumPy, PyTorch, CUDA builds). Without isolated environments you will eventually break one project by upgrading another. Pick one tool and use it for every project.

Environment options

  • venv + pip: built into Python, fine for most CPU work. Pin versions in requirements.txt.
  • uv: a very fast drop-in for pip/venv with lockfiles; a great modern default.
  • conda / mamba: useful when you need non-Python binaries (CUDA toolkits, GDAL).

Jupyter

Notebooks are ideal for exploration: run a cell, look at a plot, adjust. JupyterLab, VS Code notebooks and Google Colab (free GPU) are all fine. Learn the kernel concept, magic commands like %timeit, and restarting the kernel to confirm your notebook runs top to bottom.

Pitfalls

  • Hidden state: cells run out of order produce results nobody can reproduce. Use Restart and Run All before trusting a result.
  • Installing packages into the global interpreter or mixing conda and pip carelessly.
  • Keeping all logic in notebooks forever. Move stable code into .py modules and import it.

Good enough to move on when you can create a fresh environment from a requirements or lock file on a new machine and reproduce a notebook result.

Key concepts

  • venv and pip
  • uv: Fast installs and lockfiles
  • conda or mamba
  • JupyterLab and VS Code notebooks
  • Google Colab and Kaggle notebooks: Free GPUs
  • Pinning and lockfiles

Mini project

Create a project folder with a pinned environment, a notebook that loads a dataset, and a README explaining how a teammate recreates the environment and runs the notebook end to end.

Check yourself

Your notebook gives a different result after Restart and Run All. What most likely happened?

Free resources