Install notebook packages with %pip in the running kernel
Short answer
D Use %pip, which installs packages through the Azure Machine Learning notebook's currently running kernel interpreter.
Question
Key Takeaways
Installing packages in an Azure Machine Learning studio notebook requires the %pip magic, because it runs pip through the currently running kernel's interpreter and keeps packages scoped to that kernel. !pip and !conda are shell escapes that may resolve to a different Python executable or environment, while %load only loads code into a cell. %pip is the correct choice whenever installation must be limited to the active kernel.
Expert Analysis
The %pip magic runs package installation in the context of the notebook's current Python kernel. This keeps the installation aligned with the interpreter that is executing the notebook, which satisfies the kernel-specific requirement. A shell command such as!pip can resolve to a different executable, while %load does not install packages.
The deciding constraint here is that installation must be confined to the currently running kernel of the Azure Machine Learning studio notebook. The %pip magic is the Jupyter/IPython line magic that invokes pip through the active kernel's interpreter, so every package it installs lands in the site-packages that the executing kernel actually imports from. That is exactly what "limited to the currently running kernel only" demands, which makes D the correct choice.
Option A, !pip, is a shell escape: IPython runs it as a child shell process, and the pip on PATH may belong to a different Python installation than the kernel's interpreter. In a cloud notebook environment that mismatch is common, so packages can be installed successfully yet remain invisible to import in the notebook. Option B, !conda, is also a shell escape and additionally targets an entire conda environment rather than the single running kernel, so it fails both halves of the requirement. Option C, %load, is the magic that loads code from a file, a URL or the clipboard into a cell for editing — it performs no installation at all, so it is irrelevant to installing packages.
One mechanism this question relies on but never states: IPython treats % magics and ! shell escapes differently. Magics are handled by the kernel process itself, so %pip resolves sys.executable and runs python -m pip under that interpreter; !pip is parsed as a system command and resolved by the shell environment. Worked example: if the Azure ML kernel runs on Python 3.11 in one location while the notebook server's PATH points pip at Python 3.9, then %pip install pandas puts pandas where the 3.11 kernel can import it, whereas !pip install pandas may install into 3.9 and the subsequent import pandas in the notebook still fails.
The practical exam technique is to read the qualifier in the stem as a filter. Words such as "currently running kernel", "this notebook's environment", or "the active session" signal a % magic (typically %pip or %conda), while wording about a shell, a remote host, or a system-wide install signals !. Load and read magics (%load, %run, %matplotlib) are distractors when the task verb is install.
So D is right because only %pip guarantees the installation is performed by, and for, the kernel that is executing the notebook.
Official Reference
https://ipython.readthedocs.io/en/stable/interactive/magics.html
This link opens the official vendor documentation in a new tab.
Exam Strategy
In IPython and Azure ML notebook questions, treat a stem qualifier like "currently running kernel" or "this environment" as a signal to pick a % magic over a ! shell escape. Ask whether the action must be handled by the kernel process itself: pip installs and environment queries belong to magics such as %pip, whereas shell escapes resolve a PATH executable that may differ from the kernel's interpreter. Also eliminate options whose verb does not match the task — %load reads code rather than installing anything.
Related Analysis
Practice All AI-300 Questions
Access 49 questions with complete answers and detailed explanations.
View Full AI-300 Practice Test →