【Python】window10 python rarfile

rarfile是第三方库。需要先安装rarfile该第三方库

pip install rarfile

使用rarfile解压相应的rar文件

import rarfile
path = r'C:\Users\zhengruiping\py_operate_ftp\test_ftp_data\t'
os.chdir(path)
rf = rarfile.RarFile('20191030.rar')
rf.extractall(path)
rf.close()

运行如上代码会报错。错误如下:

原因是:python的执行目录下缺少UnRAR.exe该文件

解决方案:在计算机中搜索该文件UnRAR.exe。并将其放到python的执行目录下。我的为:C:\ProgramData\Anaconda3\

再运行如上代码。解决!!!

猜你喜欢

转载自blog.csdn.net/xiezhen_zheng/article/details/103035245