I am new to google colab and i am figuring out if google colab is able to access files on my computer's cdrive directly.
import os
path = 'C:\\Users\\guest\\Desktop\\'
for file in os.listdir(path):
print(file)
The error message that come out is [Errno 2] No such file or directory: 'C:\Users\zhuan.lim\Desktop\script tools\Python Scripts\'
I searched online and some examples said to upload the files first using:
from google.colab import files
uploaded = files.upload()
However, is there another way for google colab to directly read from my drives?
Thanks in advance.
You can make Google Colab access the files on your computer essentially in three ways:
from google.colab import files
uploaded = files.upload()
from google.colab import drive
drive.mount('/content/gdrive')
!ls ./content/gdrive
Once loaded, click on Files on the left pane to access the file-structure, as shown in the following screenshot.
Note: Alternatively, click on Files >> Mount Drive and this will insert the code-snippet to mount Google Drive into your Colab Notebook. Once you run that cell, you will see GDrive getting mounted.
I will explain option#3 below.
Colab offers you to connect to a local runtime. If you have installed jupyter_http_over_ws
as explained here you should be able to just provide the port you used to start the local runtime and connect to it from colab.
Click on Reconnect and then select "Connect to local runtime". (Top right corner in colab).
Click on hyperlink: these instructions, in the pop-up as shown below (in step-3), to install jupyter_http_over_ws
, if not already installed.
jupyter_http_over_ws
jupyter extension (one-time).pip install jupyter_http_over_ws
jupyter serverextension enable --py jupyter_http_over_ws
New notebook servers are started normally, though you will need to set a flag to explicitly trust WebSocket connections from the Colaboratory frontend.
jupyter notebook \
--NotebookApp.allow_origin='https://colab.research.google.com' \
--port=8888 \
--NotebookApp.port_retries=0
For more details, I encourage you to see these instructions.
Provide the correct port number (e.g. 8888) that was used to start the local runtime (jupyter notebook on your local machine).