Search code examples
google-colaboratory

ERROR trying to load Data to Google Collab from disk


i am trying to open and load some data from disk in Google Collab but i get the following error message:


FileNotFoundError                         Traceback (most recent call last)

<ipython-input-38-cc9c795dc8d8> in <module>()
----> 1 test=open(r"C:\Users\Stefanos\Desktop\ΑΕΡΟΜΑΓΝΗΤΙΚΑ PUBLICATION\data\test.txt",mode="r")

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Stefanos\\Desktop\\ΑΕΡΟΜΑΓΝΗΤΙΚΑ PUBLICATION\\data\\test.txt'

the error occurs by this code:

test=open(r"C:\Users\Stefanos\Desktop\ΑΕΡΟΜΑΓΝΗΤΙΚΑ PUBLICATION\data\test.txt",mode="r")

Solution

  • Your problem is that you are trying to load from disk with path of your computer!

    Collab gives you a completely different computer in the cloud to work with so it wont be able to open the files in your computer:

    You have to upload files to collab:

    Use this function to upload files. It will SAVE them as well.

    def upload_files():
      from google.colab import files
      uploaded = files.upload()
      for k, v in uploaded.items():
        open(k, 'wb').write(v)
      return list(uploaded.keys())