简体   繁体   中英

How to upload files to Colab from Github without using Google Drive?

I have started to use Colab. Now I want to from the notebook automatically upload a couple of smaller files from my Github repository. My idea is that I should try to upload these files directly to the workspace of the Colab virtual machine and use of Google Drive not necessary. This strategy should also facilitate sharing the notebook with others.

My Colab notebook code is as follows:

%%bash
git clone https://github.com/my_repository/folder1

%load folder1/file1.py

run -i file1.py

%load folder1/file2.zip

The first two command works fine but the two last gives error messages.

The error message when I try run file1.py is:

ERROR: root:File 'file1.py' not found.

And the error message when I try to load file2.zip

File "<string>", line unknown
SyntaxError: invalid or missing encoding declaration for 'folder1/file2.zip'

(The file2.zip contains both some text file and an executable file for linux environment)

How to solve this?

Note1. If I check the directory after the second command with !ls I see I have folder1 and when I do !ls folder1 then I see the content of that folder1. So looks ok so far.

Note2. If I mount my Google Drive and upload the folder here then I can get it all to work. But I want to avoid using Google Drive since that complicates sharing of the notebook, in my eyes.

Note3. What I can see the zip-file contains a binary that is described as ELF 64-bit LSB shared object, x86-64, version 1 (SYSV)

I found a solution I think and the code should be:

%%bash
git clone https://github.com/my_repository/folder1

%cd folder1

run -i file1.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM