Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway I can download the file in Google colaboratory?

I am trying tensorflow in Google Colaboratory from this codelab, I need to download 'http://download.tensorflow.org/example_images/flower_photos.tgz' this file to complete the lab.

How I can download the file. Is there anyway to upload the tar file without downloading it on my machine.

I tried this method

import urllib
testfile = urllib.URLopener()
testfile.retrieve("http://randomsite.com/file.gz", "file.gz")

This doesn't work, wget is not found also. Anyone please tell me how to do this.

like image 910
Anirudha Gupta Avatar asked Mar 30 '18 14:03

Anirudha Gupta


People also ask

Can you download files from Google Colab?

We can use google colab to download any file on google drive.

How do I download all files from a folder in Colab?

How to Download Folders from Colab. The command is !zip followed by r which means “recursive”, then we write the file path of the zipped file (i.e. /content/sample_data. zip ) and finally, we write the folder that we want to zip (i.e. /content/sample_data ) and voila, the zip file is generated :-).

How to download a file from Google Colab?

To download a file for Colab lib use, however, you will need to use the Google Chrome Browser. If you are using Firefox, then this won’t work. Once executed, this will download the file directly to your downloads. How to add a file into Google Drive from Google Colab workspace?

How to download a file created in Colaboratory workspace?

How to download a file created in Colaboratory workspace? To download a file you can use the Colab lib, however, you will need to use the Google Chrome Browser. If you are using Firefox, then this won’t work. Once executed, this will download the file directly to your downloads.

How to download something from Google Drive in Python 3?

1 1 : Sign in to Google Colab and Create a new Python3 notebook. 2 Step #2 : Importing google drive to colab. To import google drive, write this code in code section of colab and run it by Ctrl+Enter. ... 3 Step #3 : Download something to Google Drive. To download something all we need is URL to downloadable file. ...

What is Google Colab used for?

What is Google Colab? Google Colab or “Colaboratory” is a product from Google research. Colab allows users to write and execute Python Code useful for Data Analysis or Machine Learning. Google Colab is hosted on Jupyter Notebook so is easily accessible to users that are already familiar with Jupyter.


2 Answers

Read the manual, they have good examples and explanations: urllib.request

To download:

>>> import os
>>> import urllib.request
>>> urllib.request.urlretrieve('https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', 'google.png')
('google.png', <http.client.HTTPMessage object at 0x7fba3c4cb908>)
>>> os.listdir()
['google.png']

To just check the content:

>>> with urllib.request.urlopen('http://www.python.org/') as f:
...     print(f.read(300))
like image 22
rowan Avatar answered Nov 03 '22 00:11

rowan


Possibly simpler: use !wget, e.g., executing a cell with the command:

!wget https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png

will save the file to the local filesystem of the VM. (Note the leading !. This is a signal to execute the line as a shell command.)

like image 170
Bob Smith Avatar answered Nov 03 '22 00:11

Bob Smith