Reputation: 471
I want to mount google drive on google Colab and I am using this command to mount the drive
from google.colab import drive
drive.mount('/content/drive/')
but I am getting this error
ValueError Traceback (most recent call last)
<ipython-input-45-9667a744255b> in <module>()
1 from google.colab import drive
----> 2 drive.mount('content/drive/')
/usr/local/lib/python3.6/dist-packages/google/colab/drive.py in
mount(mountpoint, force_remount)
99 raise ValueError('Mountpoint must either be a directory or not exist')
100 if '/' in mountpoint and not _os.path.exists(_os.path.dirname(mountpoint)):
--> 101 raise ValueError('Mountpoint must be in a directory that exists')
102 except:
103 d.terminate(force=True)
ValueError: Mountpoint must be in a directory that exists
Upvotes: 21
Views: 91774
Reputation: 1
You indicated you typed the right command
from google.colab import drive
drive.mount('/content/drive/')
Read the -----> it indicates you that what ever you typed during the time of your code snippet, line 2 has the error and its not your code you mentioned. the / needed to be there before the word content. Good luck.
ValueError Traceback (most recent call last)
<ipython-input-45-9667a744255b> in <module>()
1 from google.colab import drive
----> 2 drive.mount('content/drive/')
Upvotes: 0
Reputation: 1
This can happen if you haven't mounted the drive previously but had a path that led to saving your data in the drive. So now, as colab doesn't have access to your drive, it will create a directory with the same names as your path and then save it in the colab session. Now, if you want to mount the drive now, it will have issues because the same path is referred but to two different locations.
Easy fix for this is to:
a.) Delete the files from your sessions in the colab
or
b.) Rename drive named folder in your colab session.
Now try to mount again. You should be good to go.
Upvotes: 0
Reputation: 13
WARNING: Make sure to read my explanation before running the command below
I ran into this error today and the reason was that Google Colab for some reason kept some folders and files from the previous session (probably because I created the folders from within the notebook). These files and folders were still being shown via the "Folders" menu, but no other GDrive files were, as I hadn't authenticated again. Even the "force_remount=True"
option didn't work.
To fix this, I simply deleted the remaining files from /drive/
by running the following command:
! rm -rf drive/
Then I could mount my GDrive again on the /drive/
directory:
from google.colab import drive
drive.mount('/content/drive')
Upvotes: 1
Reputation: 914
Just go to "manage section" , then terminate your current section, and try to mount again with:
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
It worked here.
Upvotes: 12
Reputation: 21
In my case, I click the folder icon on the side panel, it will show you Upload, Refresh and Mount Drive.
Then run
from google.colab import drive drive.mount('drive')
Go to this URL in a browser will appear - I sign to one of my account
Upvotes: 2
Reputation: 505
Simply use:
from google.colab import drive
drive.mount("/content/gdrive")
instead of:
from google.colab import drive
drive.mount("/content/drive/")
Upvotes: 6
Reputation: 11
just remove the '/' following the drive and it works perfectly..
That is from drive.mount('/content/drive/') to drive.mount('/content/drive')
Upvotes: 1
Reputation: 381
Replace drive.mount('/content/drive/')
by drive.mount('/content/drive')
Upvotes: 1
Reputation: 1
If mounting does not work even if absolute path /content/drive
was used, then verify that appropriate directories exist,
!mdkir -p /content/drive
Upvotes: 0
Reputation: 11
I received the error as well change to drive.mount('/content/drive')
Upvotes: 1
Reputation: 2282
@clarky: the error you got was correct tried to tell you that your usage of drive.mount() is incorrect: the mountpoint argument to drive.mount() must be an empty directory that exists, or the name of a non-existent file/directory in a directory that does exist so that the mountpoint can be created as part of the mount operation. Your usage of a relative path in drive.mount('content/drive/')
(i.e. content/drive/
) implies that the mount should happen at '/content/content/drive'
because the interpreter's default path is /content
; note the doubled content
path component there, and likely you don't already have a directory named /content/content inside of which a mountpoint named drive
could be created. The fix to your notebook code is to instead use drive.mount('/content/drive')
- note the leading /
making the mountpount path absolute instead of relative.
Upvotes: 17
Reputation: 23
Run command to unmount drive first.
!fusermount -u drive
Then try run again,
from google.colab import drive
drive.mount('/content/drive')
Upvotes: 0
Reputation: 539
I ran into this error this morning as well. I'm not sure what this commit what meant to fix but it certainly caused the error. A workaround is to copy the code for drive.py into colab, comment out lines 100
and 101
like this:
# drive.py
...
try:
if _os.path.islink(mountpoint):
raise ValueError('Mountpoint must not be a symlink')
if _os.path.isdir(mountpoint) and _os.listdir(mountpoint):
raise ValueError('Mountpoint must not already contain files')
if not _os.path.isdir(mountpoint) and _os.path.exists(mountpoint):
raise ValueError('Mountpoint must either be a directory or not exist')
# if '/' in mountpoint and not _os.path.exists(_os.path.dirname(mountpoint)):
# raise ValueError('Mountpoint must be in a directory that exists')
except:
d.terminate(force=True)
raise
...
then replace
from google.colab import drive
drive.mount('content/drive/')
with
mount('/content/drive/')
using the mount
function you copied from drive.py
Hopefully the issue gets fixed quickly enough so we can do away with this workaround.
Upvotes: 3