1313# limitations under the License.
1414
1515from sys import executable
16- from subprocess import check_call , CalledProcessError
16+ from subprocess import check_call , CalledProcessError , DEVNULL
1717from pkg_resources import get_distribution , DistributionNotFound
1818
1919
2020def install_package (package , version = "upgrade" ):
2121 result = False
2222
23- def try_install (args ):
23+ def try_install (args , suppress_stderr = False ):
2424 try :
25- check_call ([executable , "-m" , "pip" , * args ])
25+ stderr = DEVNULL if suppress_stderr else None
26+ check_call ([executable , "-m" , "pip" , * args ], stderr = stderr )
2627 return True
2728 except CalledProcessError :
2829 return False
2930
3031 if version .lower () == "upgrade" :
3132 args = ["install" , package , "--upgrade" ]
32- result = try_install (args + ["--user" ])
33+ result = try_install (args + ["--user" ], suppress_stderr = True )
3334 if not result :
3435 result = try_install (args )
3536 else :
@@ -41,7 +42,7 @@ def try_install(args):
4142 pass
4243 install_version = f"{ package } =={ version } " if ">=" not in version else f"{ package } { version } "
4344 args = ["install" , install_version ]
44- if not try_install (args + ["--user" ]):
45+ if not try_install (args + ["--user" ], suppress_stderr = True ):
4546 result = try_install (args )
4647
4748 return result
0 commit comments