Skip to content
tezvyn:
Menu

Why avoid global Python dependencies for ML, and how do containers help?

MediumHow cards are made

This probes environment isolation and reproducibility in ML. A strong answer cites global dependency conflicts, system library skew, and brittle environments; then notes containers freeze the full stack for deterministic deployment.

What's really being asked

This question probes whether you understand the difference between language-level isolation and full system-level isolation in machine learning workflows. Interviewers want to see that you recognize why virtualenv alone is insufficient for production ML and that you can articulate the specific reproducibility and portability problems containers address.

The full answer

First, global installations create diamond dependency conflicts where one project requires NumPy 1.24 and another requires NumPy 1.26, leading to broken environments. Second, host machines accumulate stale system libraries and compiler toolchains over time, so a pip install that succeeds on your laptop may fail on a colleague's machine or in CI because of missing libgomp or BLAS versions. Third, ML workflows often depend on specific CUDA, cuDNN, and Python interpreter versions that are painful to swap on a shared host. Fourth, containerization solves this by bundling the operating system, system libraries, Python runtime, and pip dependencies into an immutable image, turning environment setup into a single deterministic build step rather than a snowflake configuration script.

The mistakes people make

Treating Docker as just a heavyweight virtualenv replacement without mentioning system library isolation or immutability. Claiming containers solve everything while ignoring that the host kernel and GPU drivers must still be compatible with the container's CUDA expectations. Suggesting that pip install user is a sufficient fix, which ignores system dependency drift. Failing to mention reproducibility or deployment parity between training and serving environments.

What usually comes next

How would you handle a scenario where your container image is ten gigabytes because of heavy ML base images? When would you prefer conda over pip inside a container? How do you manage secrets and data volume mounts without baking them into the image? What is your strategy for multi-stage builds to keep production images small?

A concrete example

Imagine you are training a transformer model that requires PyTorch 2.1 with CUDA 11.8, while your legacy segmentation service needs PyTorch 1.13 with CUDA 11.3. Installing both globally on the same workstation is nearly impossible without constant environment switching. By building two separate Docker images, each pins the exact NVIDIA base image, the correct Python version, and a locked requirements file. When a new team member pulls the repo, docker build produces an identical environment to yours, and when Kubernetes schedules the training pod, the node only needs the matching NVIDIA driver while the container brings its own CUDA toolkit.

Interview question

Why might a project's pip install succeed in a local virtualenv yet fail in CI even with an identical requirements.txt?

  • a.Virtualenv does not lock transitive pip dependencies, so newer versions may be pulled in on the CI machine.
  • b.Virtualenv cannot prevent diamond dependency conflicts when projects need different versions of the same package.
  • c.Virtualenv isolates Python packages but still relies on the host's system libraries and compilers, which may differ across machines.Correct
  • d.Containers bundle their own NVIDIA drivers and kernel modules, eliminating hardware compatibility issues.
Why?

Virtualenv isolates pip packages but not system libraries or compilers, so missing libgomp or BLAS on CI can still cause failures; containers bundle the full OS stack to prevent this. Option B is wrong because diamond dependency conflicts arise from global installations, which virtualenv actually prevents by giving each project its own Python environment.

Just read this? Test yourself on what you have been reading.

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on mlops — each one lists the topics its interview covers.

See open roles