Usr6 Posted June 30, 2014 Report Posted June 30, 2014 Poate fi inclus la inceputul oricarui script python ce utilizeaza module care nu sunt instalate default. Pentru instalarea modulelor lipsa foloseste pip. Momentan disponibil doar pentru sistemul de operare windows & python 2.7import sysimport os######################################## RST Self installing missing modules ## Usr6 # ########################################pentru ca uneori numele modulului difera de numele pachetului:librarie = {"modul":"nume pachet", "bs4":"beautifulsoup4"}def install_module(e): module = str(e).split()[-1] raw_input("Lipseste modulul %s, apasa Enter pentru a incerca instalarea lui automata..." %module) if os.name == "nt": if not os.path.isfile('C:\\Python27\\Scripts\\pip.exe'): sys.exit("N-ai pip, n-ai noroc. Il gasesti aici: https://pypi.python.org/pypi/pip") os.system ('C:\\Python27\\Scripts\\pip.exe install "%s"' %(librarie[module])) #restarting script os.system('echo restarting... && %s "%s"' %(sys.executable, sys.argv[0])) sys.exit() elif os.name =="linux": sys.exit('%s ..."inca" NU, trebuie sa instalezi manual pachetul %s \ngoogle is your friend' %(os.name, librarie[module])) else: sys.exit('%s ..."inca" NU, trebuie sa instalezi manual pachetul %s \ngoogle is your friend' %(os.name, librarie[module]))try: #import module externe from bs4 import BeautifulSoupexcept Exception as d41d8cd98f00b204e9800998ecf8427e: install_module(d41d8cd98f00b204e9800998ecf8427e)#your script start hereprint """### ### ### # # # #### ### ### # ## # ### #forums"""raw_input("Press Enter/Return to exit...")sys.exit() Quote