diff --git a/news/4490.feature b/news/4490.feature new file mode 100644 index 00000000000..1982ef97766 --- /dev/null +++ b/news/4490.feature @@ -0,0 +1 @@ +Display a message to run the right command for modifying pip on Windows diff --git a/pip/basecommand.py b/pip/basecommand.py index 2892e2b7e02..2e47c42888f 100644 --- a/pip/basecommand.py +++ b/pip/basecommand.py @@ -314,6 +314,23 @@ def populate_requirement_set(requirement_set, args, options, finder, 'You must give at least one requirement to %(name)s ' '(see "pip help %(name)s")' % opts) + # On Windows, any operation modifying pip should be run as: + # python -m pip ... + # See https://github.com/pypa/pip/issues/1299 for more discussion + should_show_use_python_msg = ( + sys.platform == 'win32' and + requirement_set.has_requirement('pip') and + "pip" in os.path.basename(sys.argv[0]) + ) + if should_show_use_python_msg: + new_command = [ + sys.executable, "-m", "pip" + ] + sys.argv[1:] + raise CommandError( + 'To modify pip, please run the following command:\n{}' + .format(" ".join(new_command)) + ) + def _build_package_finder(self, options, session, platform=None, python_versions=None, abi=None, implementation=None):