def autoinstall(name, package=None): if not package: package = name if args.auto_install: try: import pip except ImportError: raise SystemExit("""\ Can not autoinstall as PIP is not avaliable. To install 'pip' please ask your administrator to install the package 'python-pip' or run: # sudo apt-get install python-pip """) from pip.req import InstallRequirement install = InstallRequirement(package, None) install.check_if_exists() if install.satisfied_by is None: print "Unable to find %s, autoinstalling" % (name, ) if install.conflicts_with: raise SystemExit(""" Can't install %s because it conflicts with already installed %s. Please try installing %s manually with: # sudo pip install --upgrade %s """ % (name, install.conflicts_with, name, package.replace(">", "\>"))) ret = subprocess.call(["pip", "install", "--user", package]) if ret == 0: # UNKNOWN_ERROR # Restart python is a nasty way, only method to get imports to # refresh. python = sys.executable os.execl(python, python, *sys.argv) else: raise SystemExit(""" Unknown error occurred. Please install the Python %s module. # sudo pip install %s """ % (name, package.replace(">", "\n")))
def autoinstall(name, package=None): if not package: package = name if args.auto_install: try: import pip except ImportError: raise SystemExit("""\ Can not autoinstall as PIP is not avaliable. To install 'pip' please ask your administrator to install the package 'python-pip' or run: # sudo apt-get install python-pip """) from pip.req import InstallRequirement install = InstallRequirement(package, None) install.check_if_exists() if install.satisfied_by is None: print "Unable to find %s, autoinstalling" % (name,) if install.conflicts_with: raise SystemExit(""" Can't install %s because it conflicts with already installed %s. Please try installing %s manually with: # sudo pip install --upgrade %s """ % (name, install.conflicts_with, name, package.replace(">", "\>"))) ret = subprocess.call(["pip", "install", "--user", package]) if ret == 0: # UNKNOWN_ERROR # Restart python is a nasty way, only method to get imports to refresh. import sys, os python = sys.executable os.execl(python, python, *sys.argv) else: raise SystemExit(""" Unknown error occurred. Please install the Python %s module. # sudo pip install %s """ % (name, package.replace(">", "\n")))