I can't unpack a .rar file using patoolib in Python. I always get the error message:
PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
I'm using macOS, Anaconda Navigator with Spyder IDE, and I have already installed unrar package. I don't understand why patool can't find the executable program and I'm not able to solve this problem.
Can someone tell me how to solve?
EDIT:
The error arises when I call this method, that I defined to unpack both .zip and .rar files:
def unzip_file(path_to_file, out_dir):
# Extracts path_to_file in out_dir
if path_to_file[-3:] == 'zip':
with zipfile.ZipFile(path_to_file, 'r') as zip_ref:
zip_ref.extractall(out_dir)
return
if path_to_file[-3:] == 'rar':
patoolib.extract_archive(path_to_file, outdir=out_dir)
return
raise FileNotFoundError(path_to_file)
You're on macOS, you should probably installHomebrew if it's not installed, and then run
brew install 7z
and try again.I'm guessing that this tool you're using doesn't do the actual archiving, it just knows how to talk to the various archive programs out there, and so you need to have installed one that can read and write
RAR
archives.