Kas*_*sra 10 python google-drive-api jupyter-notebook kaggle google-colaboratory
在 google colab 中,我可以轻松地安装我的 google 驱动器:
from google.colab import drive
drive.mount('/content/gdrive')
Run Code Online (Sandbox Code Playgroud)
然而,在 kaggle 的笔记本中,它给出了这个错误:
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'
Run Code Online (Sandbox Code Playgroud)
这是我在kaggle笔记本设置(也测试了这个,没工作):
!pip install google-colab # I don't know if this is the correct package
from google.colab import drive
drive.mount('/content/gdrive')
Run Code Online (Sandbox Code Playgroud)
实际上,google-colabKaggle Kernel 中并不存在该库。这样,我在Kaggle Kernel中使用如下程序来处理这个问题:
首先,从谷歌驱动器中提取您想要的文件的 ID:
接下来,gdown使用conda以下命令安装PyPI 模块:
! conda install -y gdown
最后,使用gdown和预期的 ID下载文件:
!gdown --id <put-the-ID>
例如:
!gdown --id 1-1wAx7b-USG0eQwIBVwVDUl3K1_1ReCt