2

I am trying to unrar a file using pyunpack but I always get an error. If I use a zip file everything works just fine but with rar files not. This is my code:

from pyunpack import Archive
Archive('C:/Users/Username/Desktop/teste/Desktop2.rar').extractall('C:/Users/Username/Desktop/teste')

This is the error I get:

Traceback (most recent call last):
  File "c:\Python34\lib\site-packages\easyprocess\__init__.py", line 255, in start
    cwd=self.cwd,
  File "c:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "c:\Python34\lib\subprocess.py", line 1112, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system couldn't find the specified file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Username\Documents\NetBeansProjects\Teste\src\main.py", line 17, in <module>
    Archive('C:/Users/Username/Desktop/teste/Desktop2.rar').extractall('C:/Users/Username/Desktop/teste')
  File "c:\Python34\lib\site-packages\pyunpack\__init__.py", line 81, in extractall
    self.extractall_patool(directory)
  File "c:\Python34\lib\site-packages\pyunpack\__init__.py", line 47, in extractall_patool
    ]).call()
  File "c:\Python34\lib\site-packages\easyprocess\__init__.py", line 223, in call
    self.start().wait(timeout=timeout)
  File "c:\Python34\lib\site-packages\easyprocess\__init__.py", line 260, in start
    raise EasyProcessError(self, 'start error')
easyprocess.EasyProcessError: start error <EasyProcess cmd_param=['patool', 'extract', Path('C:\\Users\\Username\\Desktop\\teste\\Desktop2.rar'), Path('--outdir=C:\\Users\\Username\\Desktop\\teste')] cmd=['patool', 'extract', Path('C:\\Users\\Username\\Desktop\\teste\\Desktop2.rar'), Path('--outdir=C:\\Users\\Username\\Desktop\\teste')] oserror=[WinError 2] The system couldn't find the specified file returncode=None stdout="None" stderr="None" timeout=False>

Do you have any idea on what could be the problem?

João Alves
  • 185
  • 1
  • 5
  • 14
  • Try installing the `patool` package. Without it, only zip files can be unpacked. – fenceop Apr 16 '15 at 14:39
  • 1
    Already did that. Did 'pip install patool' again and it says that the "Requirement is already satisfied" so I think that that is not the problem. – João Alves Apr 16 '15 at 14:41
  • I get the same error and I don't know what's causing it, sorry. – fenceop Apr 16 '15 at 15:00
  • As a temporary solution, you can use `patool` to unrar your files. See [this answer](http://stackoverflow.com/a/26178369/2202669). – fenceop Apr 16 '15 at 15:02
  • 2
    I tried that one before. It's the same thing, it can decompress zip files but not rar files: `raise util.PatoolError("could not find an executable program to %s format %s; candidates are (%s)," % (command, format, ",".join(programs))) patoolib.util.PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z)` Did you manage to get it to work with that answer? – João Alves Apr 16 '15 at 15:08
  • Yes, it worked for me. That means you're missing a few libs. – fenceop Apr 16 '15 at 15:09

2 Answers2

2

The problem is probably that you don't have your unraring tool in path, meaning it can not be called from command line (which is exacly what patool does). Just put your 7-zip (or whatever else you are using) folder to the path and you're fine.

2

Running sudo apt install unrar fixed this issue for me.

JTs
  • 21
  • 5