본문 바로가기
Computer Science/Error Code

[Data Science/Colab] 코랩에서 압축 에러 발생할 경우 해결 방법: End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directo..

by Henry Cho 2023. 8. 3.
728x90

코랩에서 압축 에러 발생할 경우 해결 방법: End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of 


# End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive. unzip: cannot find zipfile directory in one of 

Colab에서 데이터 분석에 필요한 압축 파일을 가져와서 파일을 Unzip 하여 사용하려고 할 때 발생할 수 있는 에러이다. 글쓴이도 신나게 사이드 프로젝트를 하고 있는 와중에 이러한 에러를 마주쳐서 당황했지만 차근차근 과정들을 돌이켜보며 결국 문제를 해결했다. Unzip 에러의 경우가 상당히 많은 건지는 몰라도 구글에서 찾은 해결 방법들은 글쓴이 상황에서 도움이 되지 않았다. 따라서 글쓴이처럼 모든 방법을 동원해 봤는데도 문제가 해결되지 않는다면 글쓴이와 같은 상황인 경우일 수도 있다. 글쓴이는 Colab에서 torch 기반으로 작업을 하다가 압축이 풀어지지 않아 zipfile, patool 등의 다른 기능들을 사용해서 압축을 풀어보려고 했지만 실패한 케이스이다. 아래와 같이 다른 압축 푸는 기능을 사용했을 때에도 에러가 발생하였다.


BadZipFile                                Traceback (most recent call last) <ipython-input-17-2be17f3aae3f> in <cell line: 5>() 3 4 import zipfile ----> 5 with zipfile.ZipFile(zip_path, 'r') as zip: 6     zip.extractall(unzip_path) 1 frames /usr/lib/python3.10/zipfile.py in _RealGetContents(self) 1334             raise BadZipFile("File is not a zip file") 1335         if not endrec: -> 1336             raise BadZipFile("File is not a zip file") 1337         if self.debug > 1: 1338             print(endrec) BadZipFile: File is not a zip file


PatoolError                               Traceback (most recent call last) <ipython-input-23-f2a4d24d4899> in <cell line: 1>() ----> 1 patoolib.extract_archive("farmInsects.zip") 1 frames /usr/local/lib/python3.10/dist-packages/patoolib/util.py in check_existing_filename(filename, onlyfiles) 396     """Ensure that given filename is a valid, existing file.""" 397     if not os.path.exists(filename): --> 398         raise PatoolError("file `%s' was not found" % filename) 399     if not os.access(filename, os.R_OK): 400         raise PatoolError("file `%s' is not readable" % filename) PatoolError: file `plateImages.zip' was not found


# 우선 압축 파일 상태를 확인한다.

일단 글쓴이와 같은 상황인지를 파악하기 위해서는 압축 파일 자체를 확인하는 것이 좋다. 그래야지 압축 파일 자체에 문제가 없다는 걸 알 수 있다. 왜냐하면 위와 같은 에러는 압축 파일 자체에서 문제가 있을 때에도 발생하는 에러이기 때문에 이 점을 정확히 파악해 두는 것이 좋다. 압축 파일 자체에 문제가 있다면 글쓴이의 방법은 효과가 없기 때문이다. 글쓴이는 이번에 맥북을 사용하다가 발생하였기에 터미널에 들어가서 압축 파일 상태를 바로 확인해 주었다.

file 압축파일명.zip

 

farmInsects.zip: Zip archive data, at least v4.5 to extract, compression method=deflate

이런 식으로 압축 파일 자체에 문제가 없다면 압축 파일에 대한 정보를 알려준다. 글쓴이는 해충 디텍팅 사이드 프로젝트를 진행 중이라 압축 파일명이 farmInsects.zip이다. 만일 압축 파일 자체에 문제가 있다면 제대로 된 압축 파일만 다시 사용하면 쉽게 문제 해결이 가능하다.


# 기다리면 해결 끝

위와 같이 압축 파일 자체에 문제가 없고 import 한 모듈들도 제대로 작동하는데 압축 파일 에러가 지속적으로 발생한다면 기다려야 한다. 이 말이 무슨 뜻이냐면 압축 파일 자체가 코랩에 아직 완벽히 다운로드가 안 되었다는 것이다. 정말 놀랍게도 1분 정도 기다리고 다시 작업하니 압축 파일 에러가 뜨지 않았다. 너무나도 허무해서 짜증이 났지만 어쩔 수 없는 성격 급한 한국인인가 보다. torch, zipfile, patoolib에서 모두 테스트를 해본 결과 문제없이 압축 파일이 잘 풀린다.

import torch
!unzip -q "/content/farmInsects.zip" -d datasets

 

zip_path = '/content/farmInsects.zip'
unzip_path = '/content'

import zipfile
with zipfile.ZipFile(zip_path, 'r') as zip:
    zip.extractall(unzip_path)

 

patoolib.extract_archive("/content/farmInsects.zip")

코랩에 압축 파일의 다운로드가 완료된 것처럼 보이지만 사실상 완벽히 다운로드가 이루어지기 위해서는 시간이 필요하다. 특히 이미지나 영상 데이터 분석 압축 파일의 경우에는 용량이 클 수밖에 없기 때문에 다운로드가 완료되어 보인다고 할지라도 시간을 가지고 기다려줘야 한다. 글쓴이처럼 괜히 심각하게 받아들여서 고민하지 말고 글쓴이와 비슷한 상황이라면 조금만 기다렸다가 다시 작업을 해보기를 바란다. 우리 브로들이 이 포스트를 읽고 글쓴이처럼 시간을 허비하지 않는다면 그걸로 글쓴이는 만족한다. 괜히 에러 메세지를 읽다가 압축 파일에 문제가 있는 줄 알고 문제점을 찾으려고 하게 만든 에러 메시지를 자체를 볼 때마다 너무나 얄밉다. 하지만 해결 뒤에 찾아오는 쾌감은 어쩔 수 없는 컴퓨터쟁이인가 보다.


 

 

 

 

728x90

댓글