def autoUp(): for p in Environment(): try: install(['-U', '-v']+[p]) except: print "Update of %s failed!"%p print "Done!"
def stepUp(): for p in Environment(): a = raw_input("updating %s, confirm? (y/n)"%p) if a =='y': try: install(['-U']+[p]) except: print "Update of %s failed!"%p else: print "Skipping %s"%p print "Done!"
def package_installation(logger): try: reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) except: try: reqs = subprocess.check_output( [sys.executable, '-m', 'pip3', 'freeze']) except: print( "Please ensure that pip or pip3 is installed on your laptop and redo the setup" ) installed_packages = [r.decode().split('==')[0] for r in reqs.split()] config = conf_reader.get_config() requirements = config.get("requirements", None) print('packages execution started...') packages = [] try: with open(requirements, "rt") as f: for line in f: l = line.strip() package = l.split(',') package = package[0] packages.append(package) for i in packages: if i not in installed_packages: working_set = WorkingSet() try: dep = working_set.require('paramiko>=1.0') except DistributionNotFound: pass whoami = os.getlogin() if whoami == 'root': install([i]) if whoami != 'root': try: subprocess.check_call(["pip", "install", "--user", i]) except: try: subprocess.check_call( ["pip3", "install", "--user", i]) except: print( "Check whether this user has admin privileges for installing package" ) except Exception as e: logger.exception( 'ERROR:: Some issue in reading the Config...check config_reader.py script in bin Folder....' ) raise e
def checkApps(apps=[]): working_set = WorkingSet() for app in apps: manifest = getAppManifest(app) if manifest: for dependency in manifest["externalDependencies"]: try: dep = working_set.require(dependency) except DistributionNotFound: from setuptools.command.easy_install import main as install try: install([dependency]) except Exception as e: print e
def attempt_pkg_install(pkg): msg("This tool requires the {0} package to be installed. Attempting installation..." .format(pkg)) from pkg_resources import WorkingSet, DistributionNotFound working_set = WorkingSet() try: dep = working_set.require(pkg) except DistributionNotFound: try: from setuptools.command.easy_install import main as install install([pkg]) except: msg("This tool was unable to find or install a required dependency: {0}" .format(pkg)) exit
def prerequisites(package): if package == 'PyYAML': package = 'yaml' elif package == 'mctools[color]': package = 'mctools' print(package, end="") while True: try: return __import__(package) except ImportError: print(": [NO]\n") if package == 'yaml': package = 'PyYAML' elif package == 'mctools': package = 'mctools[color]' print("You are missing the module " + package + "\n(Install once and forget about it)") user_input = input("\nWould you like to install it? y/n: ") if user_input == 'y': print("Installing " + package + " via pip...", end="") install([package]) print("Done!\nPlease restart the program.") counter = 4 for count in range(3): counter -= 1 print("Exiting in..." + str(counter), end="\r") time.sleep(1) break elif user_input == 'n': print("\nThis program cannot function without " + package + ", please consider installing to continue." "\n") counter = 4 for count in range(3): counter -= 1 print("Exiting in..." + str(counter), end="\r") time.sleep(1) break exit()
def sys_install_packages(installed_packages,requirements): packages=[] with open(requirements, "rt") as f: for line in f: l = line.strip() package = l.split(',') package=package[0] packages.append(package) for i in packages: if i in installed_packages: continue log.info("The %s package is already installed" % (i)) if i not in installed_packages: working_set = WorkingSet() try: dep = working_set.require('paramiko>=1.0') except DistributionNotFound: pass whoami=os.getlogin() if whoami =='root': installPackage=install([i]) log.info("Newlly installation of %s is sucessfully done"% (installPackage)) if whoami !='root': try: installPackage=subprocess.check_call(["pip", "install","--user", i]) log.info("Newlly installation of %s is sucessfully done"% (installPackage)) except: try: installPackage=subprocess.check_call(["pip3", "install","--user", i]) log.info("Newlly installation of %s is sucessfully done"% (installPackage)) except Exception as e: e = sys.exc_info() log.error("the above error occured while installing %s package"% (e))
def go(self): working_set = WorkingSet() for pkgName in self.pkgList: try: depends = working_set.require(pkgName) except DistributionNotFound: from setuptools.command.easy_install import main as install import urllib2 print("\n Library '" + pkgName + "' needs to be installed.") allow = input(" May I install the above library? ([y]/n): ") # Prompt for user decision if a package requires installation allow = allow.upper() if allow == "N" or allow == "NO": sys.exit("\n ERROR: Please install package '" + pkgName + "' manually.\n") else: try: response = urllib2.urlopen("http://www.python.org/", timeout=10) except urllib2.URLError as err: sys.exit("\n ERROR: No internet connection available.\n") try: install(["--user", pkgName]) # Make certain to use the user flag # ALTERNATIVE: os.system("easy_install-2.7 --user " + pkgName + "==" + pkgVersion) print("\n Library '" + pkgName + "' installed successfully.") # ALTERNATIVE: print "\n Library '" + pkgName + "v." + pkgVersion + "' installed successfully." except: import os if sys.platform == "linux" or sys.platform == "linux2": if isExe("pip2.7"): os.system("pip2.7 install " + pkgName + " --user") else: ("\n ERROR: Python setuptools inaccessible.\n") elif sys.platform == "darwin": if isExe("pip2.7"): os.system("pip2.7 install " + pkgName + " --user") else: ("\n ERROR: Python setuptools inaccessible.\n") elif sys.platform == "win32": if isExe("pip2.7.exe"): os.system("pip2.7.exe install " + pkgName) else: ("\n ERROR: Python setuptools inaccessible.\n") try: exec("import " + pkgName) except ImportError: sys.exit("\n Please restart this script.\n") # After installation via easy_install, Python must be restarted for certain new modules to be properly loaded
def initialSetup(): from pkg_resources import WorkingSet, DistributionNotFound workingSet = WorkingSet() requirements = ['psutil'] print 'Checking dependencies......' for requirement in requirements: try: dep = workingSet.require(requirement) print 'Dependency found....' print 'Countinuing to the program...' except DistributionNotFound: print 'Installing dependencies...' from setuptools.command.easy_install import main as install try: install([requirement]) print 'Dependency installed...' print 'Continuing....' except Exception: print 'Coudn\'t install dependencies...'
# print tuple(working_set) # Detecting if module is installed dependency_found = True try: dep = working_set.require('Jinja2') except DistributionNotFound: dependency_found = False pass if not dependency_found: try: # Installing it (anyone knows a better way?) from setuptools.command.easy_install import main as install install(['Jinja2']) print("run again as normal user to process results") except DistributionNotFound: print("run this script as sudo to install a missing template engine") pass sys.exit(0) import csv import subprocess import time import os import json import jinja2 ################################################################################ # Constant and parameters
def main(): for pkg in req_list: try: __import__(pkg) except ImportError: install([pkg])
from getpass import getpass from validate_email import validate_email except ImportError: print "Installing required libraries." from setuptools.command.easy_install import main as install req_list = [ 'sys', 'imaplib', 'getpass', 'email', 'datetime', 'requests', 'json', 'googlemaps', 'datetime', 'time', 'xml', 're', 'validate_email' ] for pkg in req_list: try: __import__(pkg) except ImportError: install([pkg]) ''' Uses imaplib to fetch emails. Returns a dictionary of senders mapped to an array of emails they've sent. ''' def getBySender(conn, numEmails): emails = {} conn.select('inbox') result, data = conn.uid('search', None, "ALL") if result == "OK": uid = data[0].split() if numEmails > len(uid): numEmails = len(uid) for i in range(0, numEmails):
from pkg_resources import WorkingSet, DistributionNotFound working_set = WorkingSet() # Printing all installed modules print tuple(working_set) # Detecting if module is installed try: dep = working_set.require('paramiko>=1.0') except DistributionNotFound: pass # Installing it (anyone knows a better way?) from setuptools.command.easy_install import main as install install(['django>=1.2'])
# required packages for executing the program is collecting from ../lib/requirement.txt then installing the package # requirements=["selenium","pandas","mysql-connector-python","times","datetime","beautifulsoup4"] packages = [] with open(requirements, "rt") as f: for line in f: l = line.strip() package = l.split(',') package = package[0] packages.append(package) for i in packages: if i not in installed_packages: working_set = WorkingSet() try: dep = working_set.require('paramiko>=1.0') except DistributionNotFound: pass whoami = os.getlogin() if whoami == 'root': install([i]) if whoami != 'root': try: subprocess.check_call(["pip", "install", "--user", i]) except: try: subprocess.check_call(["pip3", "install", "--user", i]) except: print( "Check whether this user has admin privileges for installing package" )
#!/usr/bin/env python3.6 # -*- coding: utf-8 -*- from setuptools.command.easy_install import main as install SELENIUM_PACKAGES = ['facebook-sdk', 'pip', 'selenium', "requests"] TOTAL_PACKAGES = len(SELENIUM_PACKAGES) i = 0 for i in range(0, TOTAL_PACKAGES): PACKAGE = SELENIUM_PACKAGES[i] install([PACKAGE])
import os import sys import time import _thread as thread import msvcrt try: __import__('rich') except ImportError: print("Installing rich ") from setuptools.command.easy_install import main as install install(['rich']) from rich.console import Console from rich.table import Column, Table from rich.columns import Columns from rich.live import Live pictures0 = [" \n"\ " \n"\ " \n"\ " * \n"\ " ** \n"\ " *..* \n"\ " * -* \n"\ " * ** * \n"\ " *** ****** ** \n"\ " * * * * \n"\ " * * \n"\ " ************ \n"\ " * * \n"\
# -*- coding: utf-8 -*- import subprocess from pkg_resources import WorkingSet, DistributionNotFound from setuptools.command.easy_install import main as install working_set = WorkingSet() # Detecting if module is installed try: dep = working_set.require('nb_pdf_template') except DistributionNotFound: print("Starting one-time install of templates for your PDF export.") install(['nb_pdf_template']) subprocess.Popen(["python", "-m", "nb_pdf_template.install", "--minted"])
from pkg_resources import WorkingSet , DistributionNotFound working_set = WorkingSet() # Printing all installed modules print tuple(working_set) # Detecting if module is installed try: dep = working_set.require('paramiko>=1.0') except DistributionNotFound: pass # Installing it (anyone knows a better way?) from setuptools.command.easy_install import main as install install(['django>=1.2'])
def moduleinstall(name): install([name]) print("Restarting Process!.") os.execl(sys.executable, sys.executable, *sys.argv)
'../Scripts'): #Check if the folder exists otherwise make it os.mkdir('../Scripts') for file in files: #Copy makeSimilarScripts to top level Scripts shutil.copy2('./EXOSIMS/Scripts/' + file, '../Scripts/' + file) shutil.copy2('./EXOSIMS/util/makeSimilarScripts.py', '../Scripts/' + 'makeSimilarScripts.py') #### Part 2 cache ######################################### #This folder is temporarily created to house files generated by EXOSIMS which are designed to be continually appended to or overwritten if not os.path.isdir( '../cache'): #Check if the folder exists otherwise make it os.mkdir('../cache') #### Part 3 FIT FILES ##################################### #This folder is designed *in the future* to house fit files for telescope instruments if not os.path.isdir('../fitFilesFolder' ): #Check if the folder exists otherwise make it os.mkdir('../fitFilesFolder') #### If packages not installed, install them #pip.main(['install','-r','./requirements.txt']) with open('./requirements.txt') as g: reqs = g.readlines() for line in reqs: install(line.split()) ### Set Python Path ############# ### Download h5 fitting parameters file to planetPhysical Model #Download HLC fit files from IPAC WFIRST website #Download de432.bsp file fromJPL
loading(2) clear() print('###########################################################################') print('# All Packages that are installed are shown below this #') print('###########################################################################') print (s.modules.keys()) print('###########################################################################') print('# All Packages that are installed are shown above this #') print('###########################################################################') continu() ru_pythonn = False try: dep = working_set.require('pyicloud') except DistributionNotFound: from setuptools.command.easy_install import main as install install(['pyicloud']) pass time.sleep(1) clear() print('RETURNING TO SETUP') time.sleep(1) elif ru_pythonn.upper() == 'N': clear() print('Returning to setup!') time.sleep(1) ru_pythonn = False else: clear() print('Choose a valid option') time.sleep(1)