Rarfile python模块在尝试从*.rar fi提取内容时不断抛出错误

2024-04-30 05:52:11 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着简单地将rar文件的内容提取到另一个位置-

import rarfile

epath='C:\\Users\\sidharth.m\\Desktop\\Rar\\xyz.rar'

def unrar(file):
    rf = rarfile.RarFile(file)
    rf.extractall()

unrar(epath)

但我得到以下错误-

Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\rarfile.py", line 2816, in custom_popen raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL) rarfile.RarCannotExec: Unrar not installed? (rarfile.UNRAR_TOOL='unrar')

我已经尝试通过anaconda prompt和cmd添加和安装rarfile和unrar包,还将它们各自的路径添加到环境路径变量中,如果这还不够,我甚至将它们导入到项目文件夹中。在

你知道为什么会出现这个问题吗?在


Tags: installed文件路径内容nottoolfilerar
1条回答
网友
1楼 · 发布于 2024-04-30 05:52:11
import rarfile

rarfile_full_path='PATHTOFILE\\xyz.rar'
path_to_extract='NEW_PATH_OF_YOUR_CHOICE'

def unrar(file,path):
    rf = rarfile.RarFile(file)
    rf.extractall(path)

unrar(rarfile_full_path,path_to_extract)

而且您需要在您的机器上安装unrarbsdtar;仅使用rarfile python包是不够的

来自API文档:

Compressed files are extracted by executing external tool: either unrar from RARLAB or bsdtar from libarchive.


Ive already tried adding and installing the rarfile and unrar packages through anaconda prompt and cmd

检查是否可以先从python的命令打开命令

相关问题 更多 >