【问题标题】:Decompressing rar file in Python error在 Python 中解压 rar 文件出错
【发布时间】:2015-06-23 01:16:38
【问题描述】:

我正在尝试使用 pyunpack 解压缩文件,但总是出错。 如果我使用 zip 文件,一切正常,但 rar 文件则不行。 这是我的代码:

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

这是我得到的错误:

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>

您知道可能是什么问题吗?

【问题讨论】:

  • 尝试安装patool 包。没有它,只能解压 zip 文件。
  • 已经这样做了。再次“pip install patool”,它说“要求已经满足”,所以我认为这不是问题。
  • 我遇到了同样的错误,我不知道是什么原因造成的,抱歉。
  • 作为临时解决方案,您可以使用patool 解压缩文件。见this answer。
  • 我以前试过那个。是一样的,它可以解压缩 zip 文件,但不能解压缩 rar 文件: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) 你是否设法让它与那个答案一起工作?

标签: python rar unrar


【解决方案1】:

问题可能是你的路径中没有你的 unraring 工具,这意味着它不能从命令行调用(这正是 patool 所做的)。只需将您的 7-zip(或您正在使用的任何其他文件)文件夹放到路径中即可。

【讨论】:

    【解决方案2】:

    运行 sudo apt install unrar 为我解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2021-01-15
      • 2020-01-15
      • 2012-03-16
      • 2020-09-18
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多