How to Mount Google Drive in Google Colab

Learn how to mount Google Drive in Colab by running a short Python cell, completing Google authorization, and opening your files in the mounted folder.

Contents

Don't Miss the Good Stuff

Get tech news that matters delivered to your inbox.

To mount Google Drive in Google Colab, import drive from google.colab, run drive.mount('/content/drive'), and complete Google’s interactive authorization process. Your personal Drive files will then be accessible under /content/drive/MyDrive/.

The short version

  • Mount with Python: Run the import and mounting code in a notebook cell, then complete authorization.
  • Use the file browser: Click Mount Drive in the left-side file browser and run the mounting cell if Colab inserts one.
  • Find your files: The standard mount puts personal files under /content/drive/MyDrive/.
  • Reconnect when needed: Add force_remount=True to retry an existing connection.

Method or optionWhen to use itWhat to expect
Python code cellMount in a hosted notebookRun the code and authorize access
File browserStart from the notebook interfaceThe button may insert mounting code
Automatic remountingReturn to an eligible notebookColab may reconnect Drive automatically
Custom mount directoryChoose a different folder pathSupply a valid mount directory
Read-only mountingRead files without writing through the mountAdd readonly=True
Forced remountRetry an existing connectionAdd force_remount=True
Flush and unmountFinish using the connectionFlush pending writes and disconnect
Gemini code generationRequest code with an eligible accountReview and run the generated code
Colab VS Code extensionMount from VS CodeExecute the appended mounting snippet
Extension installation pageGet Google’s VS Code extensionInstall from the official listing
Colab CLIMount from Linux or macOSRun the mounting command for a hosted session
CLI installation repositoryGet Google’s CLIChoose a supported installation command
Administrator service controlEnable Colab for a managed accountAn administrator enables service access
Administrator Drive policyAddress a domain-policy blockAn administrator reviews the Drive integration setting

Run the mounting code in your notebook

In a Colab notebook connected to a supported hosted runtime, enter the following Python in a code cell. Keep both lines together so the import runs before the mounting call.

from google.colab import drive

drive.mount('/content/drive')

Run the cell, then complete the interactive Google authorization process.

After mounting completes, access your personal files under /content/drive/MyDrive/. Use that location when your notebook needs a path to a personal Drive file with this mount directory.

Mount from the file browser

Open the left-side file browser and click Mount Drive. If Colab inserts a mounting code cell, run that cell next. Complete the interactive Google authorization process to finish connecting Drive to the hosted runtime.

Choose a different mount directory

You can replace /content/drive with another valid mount directory. Run the following code to use /content/gdrive, then complete authorization.

from google.colab import drive
drive.mount('/content/gdrive')

Choose a path without spaces, and do not use a symbolic link as the mountpoint. An existing directory must be empty. If Colab rejects your directory for one of these reasons, choose a directory that meets those requirements and run the mounting call again.

Connect Drive with read only access

Use the read-only option when you want to read files without allowing writes through the mount. Run the following cell with readonly=True, then complete authorization.

from google.colab import drive
drive.mount('/content/drive', readonly=True)

If Drive is already mounted, unmount it first using the disconnection steps below, or add force_remount=True. To apply read-only access through a forced remount, run this version and complete authorization if requested.

from google.colab import drive
drive.mount('/content/drive', readonly=True, force_remount=True)

Reconnect or finish using the mount

To retry an existing Drive connection, run the mounting call with force_remount=True. Complete authorization again if Colab requests it.

from google.colab import drive
drive.mount('/content/drive', force_remount=True)

When you finish using the connection, run the following code to flush pending writes and unmount Drive. Wait for the operation to complete.

from google.colab import drive
drive.flush_and_unmount()

To reconnect afterward, run the standard mounting call again. Complete the interactive authorization process if requested.

drive.mount('/content/drive')

Fix managed account access blocks

If your organization-managed account needs Colab enabled, ask an administrator with the Service Settings privilege to enable it. In Google Admin console, the administrator opens Apps > Additional Google services > Colab > Service status, selects On for everyone, then clicks Save. The administrator can instead target an organizational unit or access group. Once service access is enabled, you still need to mount Drive inside Colab.

If mounting reports a domain-policy block, ask an administrator with Drive & Docs privileges to review Apps > Google Workspace > Drive and Docs > Google Drive for desktop > Enable Drive for desktop. To enable the service, the administrator checks Allow Google Drive for desktop in your organization and clicks Save. This policy controls a prerequisite for mounting; forcing a remount does not bypass organization policy.

Ask Gemini for mounting code

In AI-enabled Colab, eligible accounts aged 18 or older in supported locales can use Gemini to generate mounting code. Click the Gemini spark icon in the notebook footer and explicitly request code to mount Google Drive. Review the generated drive.mount code, run it, and complete authorization. This option still requires a supported runtime.

Mount Drive from VS Code

Install the official Google Colab extension in VS Code. Open a notebook and sign in when prompted, then click Select Kernel > Colab > Auto Connect to connect to a Colab server.

With a Colab server assigned, press Ctrl + Shift + P, or Command + Shift + P on Mac. Select Colab: Mount Google Drive to Server... from the command palette. The command appends a mounting code snippet to the active notebook. Execute that snippet and complete Google authorization to finish mounting Drive.

Use the Colab CLI on Linux or macOS

The official Colab CLI provides a command-line route on Linux and macOS. Windows is unsupported by this CLI, and mounting requires an accessible Colab-hosted session. Install the CLI with this command.

pip install google-colab-cli

If you use uv, you can install the CLI with the following command instead. Choose one installation command.

uv tool install google-colab-cli

With CLI authentication configured, create a session using the first command below, then mount Drive using the second. Complete the interactive authentication requested by the CLI.

colab new -s analysis
colab drivemount -s analysis

The default mountpoint is /content/drive. To choose a different location, supply a PATH argument to the mounting command.

Frequently Asked Questions

Will Google Drive mount automatically next time?

Colab may remount Drive when you reconnect after initially mounting and authorizing it, provided the notebook passes its security checks. Notebooks edited by another user do not automatically mount. Google’s Colab FAQ does not describe a user-facing toggle to force eligibility.

Do you need a paid Colab plan to mount Google Drive?

You can use the standard Python mounting method on both free and paid consumer Colab plans. In either case, you need a supported hosted runtime.

Can you use these mounting steps with a local runtime?

The built-in mounting method applies to supported consumer Colab hosted runtimes. Its scope excludes local runtimes, Colab Enterprise, and Marketplace VMs.

Why do older examples ask you to paste an authorization code?

Older browser-notebook instructions used an out-of-band OAuth flow that Google has blocked for production clients. Use the current interactive mounting flow instead.

Can a forced remount fix missing account permissions?

A forced remount retries the mounting operation but does not bypass account permissions. You still need to complete the required authorization.

Share