解决方案:
1 def handle_remove_read_only(func, path, exc): 2 excvalue = exc[1] 3 if func in (os.rmdir, os.remove, os.unlink) and excvalue.errno == errno.EACCES: 4 os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777 5 func(path) 6 else: 7 sys.exit(1) 8 9 10 shutil.rmtree(LocalCode, onerror=handle_remove_read_only)