2

I am a beginner in python, I am working with Google colab, I downloaded a .gz file and saved it in my desktop from MNIST database, when I want to read this file:

import tensorflow as tf
import zipfile
with zipfile.ZipFile("C:/Users/hadi.abidi/Desktop/train-images-idx3-ubyte (2).gz") as z:
  with z.open("C:/Users/hadi.abidi/Desktop/train-images-idx3-ubyte (2).gz") as f:
    train = pd.read_csv(f,header=0,delimiter="\t")
    print(train.read())

FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/hadi.abidi/Desktop/train-images-idx3-ubyte (2).gz'
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
abidi hedi
  • 21
  • 1
  • 2
  • 1
    Unless you have connected your Colab with your desktop, you need to get your data in the Colab server. Also, you should use `gzip` module instead of `ZipFile`. – norok2 Jun 25 '20 at 11:06

2 Answers2

0

Please check the path correctly and also check with below code

import gzip
f=gzip.open("C:/Users/hadi.abidi/Desktop/train-images-idx3-ubyte (2).gz",'rb')
file_content=f.read()
print(file_content)
NAGA RAJ S
  • 452
  • 4
  • 12
  • sorry you can't access your system files to colab...you have to use jupyter notebook for access your local files – NAGA RAJ S Jun 25 '20 at 12:11
0

You need to upload the file on to Colab server first:

from google.colab import files
files.upload()

This renders a widget to upload files. From there on you can run the code for bringing the content of the file on to your notebook:

with zipfile.ZipFile("train-images-idx3-ubyte (2).gz") as z:
...

This approach requires that you interact with your notebook whenever you start your notebook. In order to have a seamless execution, I would suggest to upload the file onto Github and retrieve the file from there.

samirko
  • 21
  • 4