Python standard-library module provides tools to create, read, write, append, and list a ZIP file.
Questions tagged [python-zipfile]
404 questions
1
vote
1 answer
Getting error 'NotImplementedError("That compression method is not supported")' when extracting zipfile in python3.9
I have read through the Python documentation about zip files and watched a couple of videos, but everything didn't work. I'm using Kali Linux, so that the password has to be encoded in bytes.
Here is my code, with which I have tried:
import…
user14812229
1
vote
0 answers
Different File Paths in Python ZipFile Depending on .write() vs .writestr()
I just wanted to ask quickly if the behavior I'm seeing in Python's zipfile module is expected... I wanted to put together a zip archive. For reasons I don't think I need to get into, I was adding some files using zipfile.writestr() and others using…

JSv4
- 193
- 1
- 8
1
vote
2 answers
Create a zip of folders using zipfile
I have a folder called my_folder at the following Path /Users/my_user_name/Desktop/my_folder. The folder my_folder contains more folders like 323456, 987654 etc. Those folders contain some content. I want to create a zip of all those folders called…

Sluna
- 169
- 10
1
vote
2 answers
zipfile: Adding files to encrypted zip
I have an encrypted ZIP file and for some reason, any password I feed it doesn't seem to matter as it can add files to the archive regardless. I checked for any ignored exceptions or anything, but nothing seems to be fairly obvious.
I posted the…

Vasilisa
- 131
- 1
- 10
1
vote
1 answer
Python zipfile extract files from directory inside a zip file
I need to extract some files inside a directory in a zip file.
The main problem is that I want to extract only the contents from this directory, not the directory itself with all the files inside.
I've tried by iterating on them using namelist() or…

Vladoski
- 317
- 2
- 9
1
vote
1 answer
Python's zipfile library can't extract password protected file
For some reason, Python's zipfile library cannot extract the files in this password-protected zipfile archive. Here is the code I used:
import zipfile
zip_filename =…

Felipe D.
- 1,157
- 9
- 19
1
vote
1 answer
How to cv2.imread an image within a zipfile?
I'm trying to use OpenCV2 to read images withing a zipfile with cv2.imread and then resize them and save them but I can't figure out how to read those images within the zipfile. This is my code so far:
import cv2
from zipfile import ZipFile
with…

ShubhamPlayZ
- 25
- 3
1
vote
1 answer
Why Python zipfile module creates full path inside the zip file
I need to zip all files in a given directory(inside test1) into a zip file.
My code is
import zipfile
zipf = zipfile.ZipFile('/media/test/test1/'+'my_zip.zip', 'w', zipfile.ZIP_DEFLATED)
#Here I mentioned the path for specifying where the zip file…

Vanjith
- 520
- 4
- 23
1
vote
2 answers
Access Denied to zipfile created using python
I was able to create a zip file using the below code:
import os
import zipfile
user = input('Please enter your ID:')
date = input('Please enter the date:')
os.chdir('C:/Users/'+user+'/Desktop/Files/')
name = 'Position_'+date+'_Global'
newzip =…

Akash
- 39
- 5
1
vote
2 answers
Python : extract files from zipfile from web without downloading and saving it first
import re
import requests
import zipfile
import werkzeug
werkzeug.cached_property = werkzeug.utils.cached_property
from robobrowser import RoboBrowser
br = RoboBrowser(history=True)
br.open("loginurl")
forms =…

mato200
- 75
- 6
1
vote
1 answer
Reading a pdf from a zipfile
I'm trying to get PyPDF2 to read a small .pdf file that is within a simple zip file. Here's what I've got so far:
import PyPDF2,zipfile
with zipfile.ZipFile("TEST.zip") as z:
filename = z.namelist()[0]
a = z.filelist[0]
b =…

JimmyCarlos
- 1,934
- 1
- 10
- 24
1
vote
1 answer
Passing variable to zipfile NAME
I want to assign to my zipfile from a variable named file_path, how I can do that? I tried with the code below, and this line is the problem:
with ZipFile('%s.zip' %(file_path,),'w') as zip:
Nothing happens; I get no errors just Python doesn't…

Nuevakenia
- 75
- 8
1
vote
1 answer
How to make the rest of the code wait until zipfile finishes compiling files
I'm writing a script that compresses multiple files and then uploads the zip file into Google Drive. I managed to do both of these actions separately but when I do them together the uploading begins before the files have been zipped.
# final part of…

MoreeZ
- 118
- 6
1
vote
3 answers
How to compress folders using zipfile?
My program so far is successfully able to add and compress files which are present in the same directory as test.py but there is also a folder named location in the same directory which contains additional files say citynames.txt What happens is…

Ali Khan
- 114
- 2
- 4
- 21
1
vote
3 answers
OSError Invalid argument when extracting with Python zipfile on Linux
I want to extract a file within a .zip archive to another directory. First I create a ZipFile object
zfile = '/home/.../filename.zip'
archive = zipfile.ZipFile(zfile, 'r')
The triple dot ... is me just hiding the full path, not there in the…

Russell Burdt
- 2,391
- 2
- 19
- 30