How to access files from Google Drive shared links in Colab

Need help accessing shared Drive files in Colab

I’m pretty new to Google Colab and running into an issue. Someone shared some dataset files with me through Google Drive links, and I need to load them into my Colab notebook for a machine learning project.

The shared files include:

  • Training features dataset
  • Training labels dataset
  • Testing features dataset
  • Testing labels dataset

I’ve tried a few different approaches but can’t seem to get the files to download properly into my Colab environment. What’s the best way to handle this? I’ve heard about using gdown or maybe mounting Google Drive, but I’m not sure which method works best for shared links that aren’t in my own Drive.

Any step-by-step guidance would be really helpful since I’m still learning the ropes with Colab workflows.

I had the same problem and fixed it with the gdown library. Install it with !pip install gdown then use gdown.download(url, output, quiet=False) with your shared link. Here’s what I learned: gdown handles standard sharing links fine - you don’t need to mess with URL formats most of the time. Just make sure your file permissions are set to “Anyone with the link can view” or you’ll get auth errors. For big datasets, this beats wget since it automatically handles Google’s download warnings. Large files take forever though, so be patient.

I’ve encountered similar issues when working on ML projects. To access shared Google Drive links in Colab, you need to convert them into a direct download format. Extract the file ID from the shared link, which is located between /d/ and /view in the URL https://drive.google.com/file/d/FILE_ID/view?usp=sharing. After you have the file ID, you can reformat the link as follows: https://drive.google.com/uc?id=FILE_ID. I recommend using wget, as it is available in Colab. The command will look like this: !wget "https://drive.google.com/uc?id=YOUR_FILE_ID" -O "filename.csv". Keep in mind that files larger than 25MB will require confirmation due to Google’s virus scan, so using gdown might be necessary for those cases.

just mount your drive directly if they can add files to a shared folder. run from google.colab import drive then drive.mount('/content/drive') and access everything with normal file paths. way easier than url conversions, and you won’t redownload files every runtime restart.