python – Google Colab-ValueError:Mountpoint必须位于存在的目录中

我想在谷歌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

最佳答案 @clarky:你得到的错误是正确的,试图告诉你你对drive.mount()的使用是不正确的:drive.mount()的mountpoint参数必须是一个存在的空目录,或者一个不存在的名称存在的目录中的文件/目录,以便可以在挂载操作中创建挂载点.您在drive.mount(‘content / drive /’)中使用相对路径(即content / drive /)意味着安装应该在’/ content / content / drive’进行,因为解释器的默认路径是/ content;请注意那里的doubled内容路径组件,并且您可能还没有名为/ content / content的目录,其中可以创建名为drive的挂载点.对笔记本代码的修复是使用drive.mount(‘/ content / drive’) – 注意前导/使mountpount路径绝对而不是相对.

点赞