我正在使用 Pycharm 作为我的 IDE(Python 3.7)并试图提取受密码保护的 .rar 文件(我知道密码)并已从 unrar 导入 rarfile 但收到此错误“LookupError:找不到 unrar 库的路径。”
我还尝试将导入语句更改为只说“import rarfile”,但出现以下错误“rarfile.RarCannotExec: Unrar not installed?”
我还尝试根据我在 rarfile 文档中找到的内容包含这行代码:rarfile.UNRAR_TOOL = "unrar"但是我遇到了同样的错误。
这是我的代码片段:
from unrar import rarfile
def hacker(file_path):
passwords = open('pwds.txt', 'r')
with rarfile.RarFile(file_path) as file:
for line in passwords:
try:
file.pwd = line
file.extractall()
except RuntimeError:
pass