TypeError: Cannot read property '_uploadFiles' of undefined in google colaboratory

余生颓废 提交于 2020-02-22 07:43:07

问题


I am trying to write upload the file in Google Colaboratory and I'm going to write the code as below.

from google.colab import files
uploaded = files.upload()

But I am getting the below error to run the code in browser.

MessageError: TypeError: Cannot read property '_uploadFiles' of undefined

Please help me solve the issue.


回答1:


I just tried the code snippet:

from google.colab import files
uploaded = files.upload()

and everything worked as I'd expect.




回答2:


The problem is being caused due to two things: 1.file.upload() opens up a widget. passing it to the variable somehow is not waiting for the file to be loaded. Its returning - 'MessageError: TypeError: Cannot read property '_uploadFiles' of undefined';2. the other is - this functionality seems to be working for only google chrome as of now else, it will require quite adjusting cookies as suggested in other answers. It is very time consuming unless you have done something like this before.

instead use:

files.upload()

once the files are upload, say like 'train.csv'. It can be loaded as

import pandas as pd
train = pd.read_csv('train.csv')




回答3:


In order to upload the file "YOURFILE.csv" in your directory 'YOURDIRECTORY', You can upload the directory into google drive, and do the following.

from google.colab import drive

drive.mount('/content')

Then if you see the content of your current directory, you see the "My Drive" which is your google drive and now you can have access to the files saved in your google drive. !ls command shows you the current directory content.

Now you can import your file into the current colab:

your_data = pd.read_csv("./My Drive/YOURDIRECTORY/YOURFILE.csv")




回答4:


I had the same error as yours when running the code in Colaboratory in Brave Browser. However, after switching to Google Chrome, it ran just fine. So check the browser you're running in and try another one (I tried Microsoft Edge and it didn't work, btw)




回答5:


I am having the same issue. It fails when called from inside a function. The code that fails is here

from google.colab import files

def f(fname):
    x = files.upload()
    return x[fname]
f('hello')

It works fine when I call files.upload() directly(top-level). It only fails when called from inside a function




回答6:


I was having the same problem a minute ago and, although I was not able to catch the error, there is an alternative to the file uploading method you are using.

You can just upload your file in Colab by clicking the folder icon at the notebook's sidebar and then clicking the upload button.

To load your file into a cell, for example a csv file, you can just write (if you are using pandas):

df = pd.read_csv('path_to/my_file.csv')

this should be browser agnostic.



来源:https://stackoverflow.com/questions/48048279/typeerror-cannot-read-property-uploadfiles-of-undefined-in-google-colaborato

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!