Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download file created in Colaboratory workspace?

I found many hints how to upload data into Colaboratory.

But now I want to do opposite -> I want to download .csv I've created in Colaboratory workspace.

How to do this?

like image 608
F1sher Avatar asked Feb 13 '18 19:02

F1sher


People also ask

How do I download a file from 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 :-).

Where does Google colab save files to?

Colab allows you to save your work to Google Drive or even directly to your GitHub repository.


3 Answers

Use files colab lib

from google.colab import files
files.download('example.txt') 

PS: use chrome browser

like image 118
nidhin Avatar answered Oct 16 '22 20:10

nidhin


You can use the file manager panel.

Use View > Table of contents to show the sidebar then click the Files tab. Right-click the file and select Download.

Google Colab file panel

Note: the process is unusual in that the download progress is not shown in the usual way in the browser. Instead it is shown by an orange circle next to the file in Colab. Only when the download is complete does it appear in the browser downloads.

Google Colab file download progress

In Firefox, it's best to keep the tab in the foreground while the download is in progress as otherwise it can fail.

like image 36
Tamlyn Avatar answered Oct 16 '22 20:10

Tamlyn


You need to add these two lines:

from google.colab import files
files.download('file.txt')

If you are using firefox, then this might not work. For making this work:

  1. from google.colab import files
  2. In next cell, print anything, like print('foo').
  3. After it has printed, erase the print line and replace it with: files.download('file.txt')

Now, it will download. This is a hacky solution told by me colleague. I don't know why it works! If you know why, please comment it.

There is a more cleaner and easier way to do this which works in both firefox and chrome.

Click on > icon. Click on files. It will display all the files and folders in your notebook. Left click on the file you want to download, choose download and you are good to go. This procedure can also be applied to upload file/folder. For uploading folder, you would have to zip it first though.

like image 19
Ayush Jain Avatar answered Oct 16 '22 20:10

Ayush Jain