Which command correctly installs Matplotlib using pip in a Python environment?
Think about the standard pip command format for installing packages.
The correct command to install Matplotlib is pip install matplotlib. Other options are either incomplete or incorrectly ordered.
What is the output of this code snippet after Matplotlib is installed?
import matplotlib print(matplotlib.__version__)
import matplotlib print(matplotlib.__version__)
If Matplotlib is installed correctly, importing it and printing its version works.
After installation, importing Matplotlib and printing matplotlib.__version__ outputs the version string. Errors occur if Matplotlib is not installed or imported incorrectly.
What error message will you get if you try to import Matplotlib without installing it first?
import matplotlib
import matplotlibThink about what Python says when a module is missing.
If Matplotlib is not installed, Python raises ModuleNotFoundError when you try to import it.
You want to install Matplotlib only for a specific project without affecting other projects. Which sequence of commands correctly creates a virtual environment and installs Matplotlib inside it?
Create the environment first, activate it, then install packages inside.
First, create the virtual environment with python -m venv env. Then activate it with source env/bin/activate (Linux/macOS) or env\Scripts\activate (Windows). Finally, install Matplotlib inside the activated environment.
You run pip install matplotlib but still get ModuleNotFoundError when importing Matplotlib in Python. Which of the following is the most likely cause?
Think about Python environments and versions.
Often, the error occurs because Matplotlib was installed for a different Python interpreter than the one used to run the code. For example, installing with pip for Python 3.8 but running Python 3.12.