gpt4 book ai didi

python - rar 文件模块在 python 2.7 中不起作用

转载 作者:行者123 更新时间:2023-11-28 22:53:56 25 4
gpt4 key购买 nike

我有这样的代码

import rarfile
pwd = None
rar = rarfile.RarFile(source_filename)
rar.extractall(dest_dir,None,pwd) # error from here

此代码在 ubuntu 中运行。当我在 Windows 上运行它时,我得到这样的错误

Traceback (most recent call last):
File "1_bete_rar.pyw", line 132, in extract
File "1_bete_rar.pyw", line 176, in unrar_file
File "rarfile.pyc", line 586, in extractall
File "rarfile.pyc", line 1112, in _extract
File "rarfile.pyc", line 1704, in custom_popen
File "subprocess.pyc", line 711, in __init__
File "subprocess.pyc", line 948, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified

我的代码有什么问题?我如何在 Windows 中使用 python 提取 rar 文件?

最佳答案

作为rarfile FAQ状态(正如堆栈跟踪中 subprocess 的痕迹所证明的那样),

[rarfile] depends on unrar command-line utility to do the actual decompression.

Note that by default it expect it to be in PATH. If unrar launching fails, you need to fix this.

所以从 http://www.rarlab.com/rar_add.htm 获取 UnRAR并将其放在您的 PATH 中的某个位置(例如您运行脚本的目录)。

关于python - rar 文件模块在 python 2.7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18767257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com