python 自动下载 moudle
import sys,re,subprocessimport os
from subprocess import CalledProcessError
new_set = set()
ls = set()
def dls():
    temp_set = set()
    a = subprocess.check_output("ls -R", shell=True)
    for line in a.split('\n'):
          str = re.sub(r'.py', r'', line)
          if  str.find('.')<0  and str!='\n' :
               temp_set.add(str)
               print str
    return temp_set
   
def dpip(new_set):
    ls = dls()
    for str in new_set-ls:
         str = str.replace('\n','')
         with open('daicy.py', 'w') as f:
                     f.write('import '+str)
         try:
              a = subprocess.check_call('python daicy.py', shell=True)
              if a!=0:
                  command = 'pip  install  '+str
                  print command
                  subprocess.call(command, shell=True)
         except CalledProcessError, e:
            print 'except:', e
            command = 'pip  install  '+str
            print command
            os.system(command)
         finally:
              pass
a = subprocess.Popen('''find -name '*.py' | xargs grep -h -o -w  -s "^import\s\+\([\_0-9a-zA-Z]\+\)\|^from\s\+\([\_0-9a-zA-Z]\+\)"''', shell=True,stdout=subprocess.PIPE)
for line in a.stdout.readlines():
    line = line.replace('\n','')
    new_set.add(re.sub(r'import\s+|from\s+', r'', line))
dpip(new_set)
        
        如果你喜欢本文, 请长按二维码,关注公众号 分布式编程.
        
        作者:分布式编程
        
        出处:https://zthinker.com/
        
        本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    
 
                    
                     
                    
                 
                    
                 
                
            
         
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号