import rarfile data_file_path = ‘C:\\data_folder\\file_name.rar’ extracted_folder = ‘C:\\TEMP’ rf = rarfile.RarFile(data_file_path) # 待解压文件
password = '123456'
rf.setpassword(pwd=password)
rf.extractall(extracted_folder)
如果出现报错:
rarfile.RarCannotExec: Cannot find working tool.
把winrar的目录设置到环境变量,重启PyCharm 就可以解决。