在kaggle笔记本中安装谷歌驱动器 [英] mount google drive in kaggle notebook
问题描述
在 google colab 中,我可以轻松地安装我的 google 驱动器:
来自 google.colab 导入驱动drive.mount('/content/gdrive')
然而,在kaggle的笔记本中,它给出了这个错误:
KeyError Traceback(最近一次调用)<ipython-input-14-2b128295b616>在<模块>2 # !pip install google-colab3 从 google.colab 导入驱动器---->4 drive.mount('/content/gdrive')5 # 在这里设置你自己的项目id6 # PROJECT_ID = 'your-google-cloud-project'挂载中的/opt/conda/lib/python3.6/site-packages/google/colab/drive.py(挂载点,force_remount,timeout_ms)80回81--->第82话83 家 = env.home第84话_env() 中的/opt/conda/lib/python3.6/site-packages/google/colab/drive.py41 家 = _os.environ['家']42 root_dir = _os.path.realpath(--->43 _os.path.join(_os.environ['CLOUDSDK_CONFIG'],'../..'))44 inet_family = 'IPV4_ONLY'45 dev = '/dev/保险丝'__getitem__(self, key) 中的/opt/conda/lib/python3.6/os.py667 除了 KeyError:668 # 使用原始键值引发 KeyError-->第669话第670回671KeyError: 'CLOUDSDK_CONFIG'
这是我在 kaggle notebook 中的设置(也测试了
然后从 URL 中提取文件的 ID:
接下来,使用 conda
安装 gdown
PyPI 模块:
<代码>!conda install -y gdown
最后,使用 gdown
和预期的 ID 下载文件:
!gdown --id
例如:
!gdown --id 1-1wAx7b-USG0eQwIBVwVDUl3K1_1ReCt
In google colab, I easily mount my google drive with this:
from google.colab import drive
drive.mount('/content/gdrive')
In kaggle's notebook, however, it gives this error:
KeyError Traceback (most recent call last)
<ipython-input-14-2b128295b616> in <module>
2 # !pip install google-colab
3 from google.colab import drive
----> 4 drive.mount('/content/gdrive')
5 # Set your own project id here
6 # PROJECT_ID = 'your-google-cloud-project'
/opt/conda/lib/python3.6/site-packages/google/colab/drive.py in mount(mountpoint, force_remount, timeout_ms)
80 return
81
---> 82 env = _env()
83 home = env.home
84 root_dir = env.root_dir
/opt/conda/lib/python3.6/site-packages/google/colab/drive.py in _env()
41 home = _os.environ['HOME']
42 root_dir = _os.path.realpath(
---> 43 _os.path.join(_os.environ['CLOUDSDK_CONFIG'], '../..'))
44 inet_family = 'IPV4_ONLY'
45 dev = '/dev/fuse'
/opt/conda/lib/python3.6/os.py in __getitem__(self, key)
667 except KeyError:
668 # raise KeyError with the original key value
--> 669 raise KeyError(key) from None
670 return self.decodevalue(value)
671
KeyError: 'CLOUDSDK_CONFIG'
This is my setup in kaggle notebook (also tested this, did not work):
!pip install google-colab # I don't know if this is the correct package
from google.colab import drive
drive.mount('/content/gdrive')
In fact, the google-colab
library does not exist in the Kaggle Kernel. In this way, I use the following procedure to deal with this problem in Kaggle Kernel:
First, extract the ID of your desire file from google drive:
In your browser, navigate to drive.google.com.
Right-click on the file, and click "Get a shareable link"
Then extract the ID of file from URL:
Next, install
gdown
PyPI module usingconda
:! conda install -y gdown
Finally, download the file using
gdown
and the intended ID:!gdown --id <put-the-ID>
For example:
!gdown --id 1-1wAx7b-USG0eQwIBVwVDUl3K1_1ReCt
这篇关于在kaggle笔记本中安装谷歌驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!