问题描述
[较新版本]:colab团队报告说,他们已于2020年5月27日更正了此问题.我已经检查过-现在可以正常使用了.
链接到问题: https://github.com/googlecolab/colabtools/issues/1205
[ Newer Edit]: colab team reported that they corrected the issue on May 27 2020.I have checked - it works Okay for me now.
Link to issue: https://github.com/googlecolab/colabtools/issues/1205
================================================ ==================
==================================================================
[新]很明显,只有通过通过Web界面按钮安装驱动器"将google驱动器安装到colab时,才会出现以下问题如果通过命令行方式安装,则不会出现.因此,似乎网络方式存在问题.请在下面的我自己的答案中查看详细信息.检查"Chrome"浏览器.
[New ] It became clear that problem below arises ONLY if mount the google drive to colab by via web interface button "Mount Drive" and does NOT appear if mount by command line way.So seems web way is bugged. See details in my own answer below. It is checked for "Chrome" browser.
================================================ ==================
==================================================================
[原始问题:]
如何从Google colab访问与我共享"? (接口现在(2020年)似乎已更改,以前描述的解决方案似乎不起作用).
How to access "shared with me" from google colab ? (Interface seems changed now (2020) and previously described solutions does not seem to work).
更多详细信息:
这个问题已经问了好几次了,描述的解决方案,例如此处: https://stackoverflow.com/a/53887376/625396 该问题我看不到添加到我的云端硬盘",而是看到添加快捷方式到云端硬盘".完成后,我们可以通过Google驱动器的网络界面看到该快捷方式的确出现.
The question has been asked several times, and the solutions described e.g. here : https://stackoverflow.com/a/53887376/625396The problem that I do not see "Add to My Drive" , but see "Add shortcut to Drive". After doing it, we can see that via web-interface for google drive, that shortcut indeed appears.
但是无法通过colab实用程序看到快捷方式,例如os.listdir()!因此,快捷方式对于colab似乎是不可见的,并且不清楚如何访问它.
BUT that shortcut canNOT be seen via colab utilities, like os.listdir() !So shortcut seems to be invisible for colab, and not clear how to access it.
以下是屏幕截图,显示colab看不到与我共享"的快捷方式-"cytotrace_datasets",但可以看到Google驱动器的网络GUI.
Below are the screenshot, showing that colab does not see the shortcut to "shared with me"-"cytotrace_datasets", but web-gui of google drive can see.
这是我通过colab看到的屏幕截图(无法看到快捷方式):
Here is screenshot what I see by colab (shortcut canNOT be seen):
这是我通过Google Drive的Web-GUI看到的屏幕截图(可以看到快捷方式):
Here is screenshot what I see by web-gui of google drive (shortcut can be seen):
推荐答案
假设您要从驱动器读取共享的csv文件.您已完成向云端硬盘添加快捷方式".
Suppose you want to read a shared csv file from drive. You have done "Add shortcut to Drive".
1)在Colab笔记本电脑上,连接到驱动器.
1) At Colab Notebook Connect to your drive.
# Import PyDrive and associated libraries.
# This only needs to be done once per notebook.
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
2)获取要访问的共享文件的ID.打开文件->转到链接共享[ https://drive.google.com/open?id= 1JKECh3GNry6xbAK6aBSzQtSntD4GTEl ]->复制'id ='之后的字符串
2) Get the id of shared file you want to access. Open file -> go to linksharing [https://drive.google.com/open?id=1JKECh3GNry6xbAK6aBSzQtSntD4GTEl ] -> copy the the string after 'id='
3)回到合作
# A file ID looks like: laggVyWshwcyP6kEI-y_W3P8D26sz
file_id = '1JKECh3GNry6xbAK6aBSzQtSntMD4GTEl'
downloaded = drive.CreateFile({'id': file_id}) #important
print(downloaded['title']) # it should print the title of desired file
downloaded.GetContentFile('file.csv')
#Finally, you can read the file as pandas dataframe.
import pandas as pd
df= pd.read_csv('file.csv')
注意:这是我对堆栈溢出问题的第一个答案
Note : This is my first ever answer to a stack overflow question
这篇关于(已解决)带有“安装驱动器"的错误web按钮在colab中.访问“与我共享" google colab中的文件(y2020,以前的解决方案似乎失败了)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!