我想在google Colab上挂载google驱动器,并且我使用这个命令来挂载驱动器。
from google.colab import drive
drive.mount('/content/drive/')但我发现了这个错误
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发布于 2019-01-17 18:08:27
@clarky:您得到的错误是正确的,试图告诉您使用drive.mount()是不正确的: drive.mount()的挂载参数必须是存在的空目录,或者是目录中不存在的文件/目录的名称,这样就可以作为挂载操作的一部分创建挂载点。在drive.mount('content/drive/')中使用相对路径(即content/drive/)意味着安装应该发生在'/content/content/drive',因为解释器的默认路径是/content;请注意那里的加倍content path组件,很可能您还没有一个名为/content/content的目录,可以在其中创建一个名为drive的挂载点。笔记本代码的修复方法是使用drive.mount('/content/drive') --注意前面的/使挂载路径是绝对的,而不是相对的。
发布于 2020-10-22 16:23:36
只需转到“管理部分”,然后终止当前部分,然后尝试重新挂载:
from google.colab import drive
drive.mount('/content/drive', force_remount=True) 它在这里起作用了。
发布于 2019-01-17 09:28:11
今天早上我也遇到了这个错误。我不知道这个提交是什么意思,但是它确实导致了错误。解决方法是将drive.py的代码复制到colab中,注释掉行100和101,如下所示:
# 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
...然后替换
from google.colab import drive
drive.mount('content/drive/')使用
mount('/content/drive/')使用从mount复制的drive.py函数
希望这个问题能够尽快解决,这样我们就可以解决这个问题了。
https://stackoverflow.com/questions/54230871
复制相似问题