You are testing an updated set of Python automation scripts on a RHEL 9 jump-box and want to avoid breaking the system packages that other administrators rely on. In one shell session you need to (1) create an isolated environment inside the current project directory, (2) activate that environment, and (3) install every dependency listed in requirements.txt. Which command sequence accomplishes all three tasks with the fewest commands?
The built-in venv module is the recommended, distribution-agnostic way to create a virtual environment.
python3 -m venv .venv creates an isolated directory named .venv that contains its own Python interpreter and site-packages.
source .venv/bin/activate modifies the PATH for the current shell so that subsequent python and pip commands use the environment instead of the system interpreter.
pip install -r requirements.txt reads every line in the requirements file and installs those packages inside the active environment.
The other choices either install packages before the environment exists, omit the -r flag (so the file would be ignored), or rely on the external virtualenv utility or the --system-site-packages switch, either of which would defeat the goal of isolation.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between `venv` and `virtualenv`?
Open an interactive chat with Bash
Why is it important to activate a virtual environment?
Open an interactive chat with Bash
What does the `-r requirements.txt` flag do in `pip install -r requirements.txt`?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access