首页 > 解决方案 > Google Colab-ValueError:挂载点必须位于存在的目录中

问题描述

我想在谷歌 Colab 上挂载谷歌驱动器,我正在使用这个命令来挂载驱动器

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

标签: pythongoogle-colaboratoryvalueerror

解决方案


@clarky:您得到的错误是正确的,试图告诉您您对 drive.mount() 的使用不正确: drive.mount() 的 mountpoint 参数必须是存在的空目录,或者不存在的名称文件/目录中确实存在的目录中,以便可以将挂载点创建为挂载操作的一部分。drive.mount('content/drive/')您在(ie )中使用相对路径content/drive/意味着安装应该发生在,'/content/content/drive'因为解释器的默认路径是/content; 请注意content那里的双路径组件,并且可能您还没有一个名为 /content/content 的目录,drive可以在其中创建一个名为的挂载点。对笔记本代码的修复是改为使用drive.mount('/content/drive')- 注意前导/使安装点路径是绝对的而不是相对的。


推荐阅读