0

I'm trying to find a way to write a df to zip file and add a password to it but I can't figure out how.

I've tried

import zipfile
archive_name='test.zip'
zf = zipfile.ZipFile(archive_name, 'w')
zf.setpassword(b"1234")

But it always says the file is in use by another process. And when I check other posts it says this is not the preferred method zipfile: how to set a password for a Zipfile?.

I'd like to only use a native library but it seems like there is no native way to do this Create password protected zip file Python. Can that really be true?

Mark McGown
  • 975
  • 1
  • 10
  • 26
  • following on from above comment, what OS are you on? because that information would influence alternative suggestions. – mechanical_meat Nov 30 '21 at 01:51
  • My current OS is windows. – Mark McGown Nov 30 '21 at 01:58
  • Ok, I recommend using 7zip with subprocess. Other SO answers have a nice explanation of doing that. You have to download 7zip unless you already have it: https://www.7-zip.org/download.html – mechanical_meat Nov 30 '21 at 02:04
  • Unfortunately I need to deploy this to an environment (still Windows) where I can't download/install external libraries. Is there any way to do this with os commands via python at least and not 7zip? – Mark McGown Nov 30 '21 at 02:12
  • I haven't seen anything without downloading libraries be they from pip or on the OS :/ – mechanical_meat Nov 30 '21 at 02:17

0 Answers0