I'm working on a program that automatically marks students' coding submissions. It includes cleaning up the submissions, setting up a virtual environment for each one, running tests, and generating a collated report. During the environment setup phase, I need to validate the contents of each requirements.txt. However, students often make mistakes, such as: Writing Python import statements inside requirements.txt, like: import torch import helper Listing incorrect package names that don’t match their pip equivalents. Copying the output of pip freeze from their global Python environment instead of a clean virtual environment, which includes unnecessary or irrelevant packages. What is the most efficient and robust way to validate a requirements.txt file in this context and ensure that the packages listed are: Valid installable pip packages Necessary (not built-in or globally irrelevant) Not misformatted (example, code instead of package specs)? Continue reading...