diff --git a/news/9915.feature.rst b/news/9915.feature.rst new file mode 100644 index 00000000000..6d7d2bc057f --- /dev/null +++ b/news/9915.feature.rst @@ -0,0 +1 @@ +Add a special error message when users forget the ``-r`` flag when installing. diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index 6e3f195187b..87e3af2de4c 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -540,6 +540,13 @@ def _report_single_requirement_conflict(self, req, parent): req_disp, ", ".join(versions) or "none", ) + if str(req) == "requirements.txt": + logger.info( + "HINT: You are attempting to install a package literally " + 'named "requirements.txt" (which cannot exist). Consider ' + "using the '-r' flag to install the packages listed in " + "requirements.txt" + ) return DistributionNotFound(f"No matching distribution found for {req}") diff --git a/tests/functional/test_install_extras.py b/tests/functional/test_install_extras.py index de1ee3795ea..83bcc548295 100644 --- a/tests/functional/test_install_extras.py +++ b/tests/functional/test_install_extras.py @@ -143,6 +143,12 @@ def test_install_special_extra(script): ) in result.stderr, str(result) +def test_install_requirements_no_r_flag(script): + '''Beginners sometimes forget the -r and this leads to confusion''' + result = script.pip('install', 'requirements.txt', expect_error=True) + assert 'literally named "requirements.txt"' in result.stdout + + @pytest.mark.parametrize( "extra_to_install, simple_version", [ ['', '3.0'],