python - Installing packages from a list using pip -
i trying install list of packages using pip.
the code used is:
import pip def install(package_name): try: pip.main(['install', package_name]) except: print("unable install " + package_name)
this code works fine , if package not available, gives error:
no matching distributions found
however, trying if installation fails (for eg: invalid package name), want print package failed.
what can done that?
any appreciated, thank you.
try checking return value non-zero, indicates error occurred install. not errors trigger exceptions.
import pip def install(package_name): try: pipcode = pip.main(['install', package_name]) if pipcode != 0: print("unable install " + package_name + " ; pipcode %d" % pipcode) except: print("unable install " + package_name)
wiki
Comments
Post a Comment