5

I am using Python 3.6, and currently I subprocess out to my 7zip program to get the compression I need.

subprocess.call('7z a -t7z -ms=off {0} *'.format(filename))

I know the zipfile class has ‘ZIP_LZMA’ compression, but the application I am passing this too says the output file isn’t correct. So what else do I have to add to the ZipFile class to make it mimic the above command?

7
  • 2
    ZIP files are different from 7Z files. Even if ZIPs might support LZMA compression these days, the files are still different. See stackoverflow.com/questions/32797851/… maybe? Commented May 21, 2018 at 13:15
  • Is there any packages to do 7zip compression? Commented May 21, 2018 at 15:17
  • @codebase5000, this library perhaps github.com/fancycode/pylzma ? Commented May 21, 2018 at 15:35
  • Pylzma is a good suggestion Commented May 21, 2018 at 23:41
  • 2
    Maybe I should increase the bounty, sounds like python really needs this functionality. Commented May 22, 2018 at 14:06

1 Answer 1

2

If you do not care much for Windows, then perhaps libarchive could help. In Ubuntu, for example:

$ sudo apt install python3-libarchive-c 

Then:

import libarchive with libarchive.file_writer('test.7z', '7zip') as archive: archive.add_files('first.file', 'second.file', 'third.file') 

Then there is the pylib7zip library, which wraps the existing 7z.dll and seems to offer a Windows-only alternative.

Sign up to request clarification or add additional context in comments.

3 Comments

Also lib archive-c seems to fail on build
Pylib7zip is a wrapper around 7z.dll, hence in theory one should be able to squeeze the compression out of it as well - the existence of the FileOutStream class does give some hope.
To build python_libarchive_c you'd probably need to install the necessary dependencies (e.g. libarchive-dev). The pre-built Ubuntu package somehow works, after all.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.