В командной строке Windows я использую 7z x test.zip -r -y -o*
, чтобы успешно распаковать мой файл.
Я пытаюсь сделать это в python с:
def extractfiles(zipname):
system = subprocess.Popen(['7z', 'x', zipname,'-r','-y','-o*'])
return(system.communicate())
os.chdir('directory_with_my_test_file')
extractfiles('test.zip')
Но получить это ошибка:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-99-7a976fc4b8be> in <module>
1 import subprocess
2 cmd = ['7z', 'x', zipname,'-r','-y','-o*']
----> 3 sp = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
4
~\AppData\Local\Continuum\anaconda3\envs\pyTorch_fast07\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
727 c2pread, c2pwrite,
728 errread, errwrite,
--> 729 restore_signals, start_new_session)
730 except:
731 # Cleanup if the child failed starting.
~\AppData\Local\Continuum\anaconda3\envs\pyTorch_fast07\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1015 env,
1016 os.fspath(cwd) if cwd is not None else None,
-> 1017 startupinfo)
1018 finally:
1019 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
Что я делаю не так ??