【问题标题】:Google Colab-ValueError: Mountpoint must be in a directory that existsGoogle Colab-ValueError:挂载点必须位于存在的目录中
【发布时间】:2019-06-11 08:30:50
【问题描述】:

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

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

【问题讨论】:

  • drive.mount('/content/drive') 自昨天(1 月 19 日)以来对我也不再有效。 Google Colab 改变了什么?我没有改变任何东西,这个命令已经工作了几个月。

标签: python google-colaboratory valueerror


【解决方案1】:

我今天早上也遇到了这个错误。我不确定commit 是什么意思,但它肯定会导致错误。一种解决方法是将drive.py 的代码复制到colab 中,注释掉100101 行,如下所示:

# 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/')

使用您从 drive.py 复制的 mount 函数

希望问题能尽快得到解决,这样我们就可以取消这种解决方法。

【讨论】:

  • 我尝试使用您的方法。但是身份验证需要永远。它不工作。
  • 身份验证的哪一部分永远耗时?
  • @Jimi:您的建议有效,因为将相对路径替换为绝对路径;注释掉是无关紧要的。
  • @clarky:如果您在身份验证过程中看到超时错误,请在github.com/googlecolab/colabtools/issues/382 上留言
  • @AmiF 不。当我失败时,我有'/content/drive'
【解决方案2】:

先运行命令卸载驱动器。

!fusermount -u drive

然后再次尝试运行,

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

【讨论】:

  • 仅供参考,而不是硬编码 fusermount 你应该使用 force_remount=True 参数到 drive.mount()
【解决方案3】:

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

【讨论】:

    【解决方案4】:

    我也收到了错误消息,改成drive.mount('/content/drive')

    【讨论】:

      【解决方案5】:

      如果即使使用了绝对路径/content/drive也无法挂载,则验证是否存在相应的目录,

      !mdkir -p /content/drive

      【讨论】:

        【解决方案6】:

        drive.mount('/content/drive/') 替换为drive.mount('/content/drive')

        【讨论】:

          【解决方案7】:

          只需删除驱动器后面的“/”即可完美运行..

          即从 drive.mount('/content/drive/') 到 drive.mount('/content/drive')

          【讨论】:

          • 您能否解释一下您的答案,以便 OP 了解他的代码中的错误。谢谢
          【解决方案8】:

          简单使用:

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

          代替:

          from google.colab import drive
          drive.mount("/content/drive/")
          

          【讨论】:

            【解决方案9】:

            在我的例子中,我点击侧面板上的文件夹图标,它会显示上传、刷新和挂载驱动器。

            1. 单击装载驱动器,即包含“我的驱动器”的“驱动器”文件夹 文件夹出现
            2. 然后运行

              从 google.colab 导入驱动器 drive.mount('驱动器')

            3. 将出现在浏览器中转到此 URL - 我登录我的一个帐户

            4. 输入您的授权码

            Drive

            【讨论】:

              【解决方案10】:

              只需转到“管理部分”,然后终止当前部分,并尝试再次安装:

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

              它在这里工作。

              【讨论】:

                【解决方案11】:

                警告:请务必在运行以下命令之前阅读我的说明

                我今天遇到了这个错误,原因是 Google Colab 出于某种原因保留了上一次会话中的一些文件夹和文件(可能是因为我从笔记本中创建了这些文件夹)。这些文件和文件夹仍然通过“文件夹”菜单显示,但没有其他 GDrive 文件,因为我没有再次进行身份验证。即使"force_remount=True" 选项也不起作用。

                为了解决这个问题,我只是通过运行以下命令从/drive/ 中删除了剩余的文件:

                ! rm -rf drive/
                

                然后我可以再次将我的 GDrive 挂载到 /drive/ 目录:

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

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 2021-05-04
                  • 2016-03-16
                  • 1970-01-01
                  • 2021-05-10
                  • 2021-04-15
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多