200-901 · Question #298
Refer to the exhibit. A developer just finished testing a Python script and wants to save the list of packages and versions installed on the current machine. The developer must make sure that it…
The correct answer is B. pip freeze > requirements.txt. The correct command is pip freeze > requirements.txt. The pip freeze command outputs all installed packages and their exact versions to stdout. The > operator is the standard shell redirect that sends stdout to a file, creating or overwriting requirements.txt. Option A uses 2>…
Question
Refer to the exhibit. A developer just finished testing a Python script and wants to save the list of packages and versions installed on the current machine. The developer must make sure that it will not cause any issues if tested on another device due to different library versions. Which line of code needs to be placed on the snippet where the code is missing?
Exhibit
Options
- Apip freeze 2> requirements.txt
- Bpip freeze > requirements.txt
- Cpip freeze => requirements.txt
- Dpip freeze | requirements.txt
How the community answered
(28 responses)- B93% (26)
- C4% (1)
- D4% (1)
Explanation
The correct command is pip freeze > requirements.txt. The pip freeze command outputs all installed packages and their exact versions to stdout. The > operator is the standard shell redirect that sends stdout to a file, creating or overwriting requirements.txt. Option A uses 2>, which redirects stderr (error output), not stdout, so the file would be empty. Option C (=>) is not a valid shell operator. Option D uses | (pipe), which passes output to another command - not to a file. Saving to requirements.txt ensures other developers can recreate the exact environment using pip install -r requirements.txt, preventing version mismatch issues.
Topics
Community Discussion
No community discussion yet for this question.
