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