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...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .