@@ -36,6 +36,14 @@ def version():
3636 """
3737 return _PIP_VERSION
3838
39+ def _clear_pip_environment_variables ():
40+ # We deliberately ignore all pip environment variables
41+ # when invoking pip
42+ # See http://bugs.python.org/issue19734 for details
43+ keys_to_remove = [k for k in os .environ if k .startswith ("PIP_" )]
44+ for k in keys_to_remove :
45+ del os .environ [k ]
46+
3947
4048def bootstrap (* , root = None , upgrade = False , user = False ,
4149 altinstall = False , default_pip = False ,
@@ -49,11 +57,7 @@ def bootstrap(*, root=None, upgrade=False, user=False,
4957 if altinstall and default_pip :
5058 raise ValueError ("Cannot use altinstall and default_pip together" )
5159
52- # We deliberately ignore all pip environment variables
53- # See http://bugs.python.org/issue19734 for details
54- keys_to_remove = [k for k in os .environ if k .startswith ("PIP_" )]
55- for k in keys_to_remove :
56- del os .environ [k ]
60+ _clear_pip_environment_variables ()
5761
5862 # By default, installing pip and setuptools installs all of the
5963 # following scripts (X.Y == running Python version):
@@ -101,7 +105,10 @@ def bootstrap(*, root=None, upgrade=False, user=False,
101105 _run_pip (args + [p [0 ] for p in _PROJECTS ], additional_paths )
102106
103107def _uninstall (* , verbosity = 0 ):
104- """Helper to support a clean default uninstall process on Windows"""
108+ """Helper to support a clean default uninstall process on Windows
109+
110+ Note that calling this function may alter os.environ.
111+ """
105112 # Nothing to do if pip was never installed, or has been removed
106113 try :
107114 import pip
@@ -114,6 +121,8 @@ def _uninstall(*, verbosity=0):
114121 "({!r} installed, {!r} bundled)" )
115122 raise RuntimeError (msg .format (pip .__version__ , _PIP_VERSION ))
116123
124+ _clear_pip_environment_variables ()
125+
117126 # Construct the arguments to be passed to the pip command
118127 args = ["uninstall" , "-y" ]
119128 if verbosity :
0 commit comments