lipao255
lipao255

Reputation: 61

FileNotFoundError: [Errno 2] No such file or directory (python error)

I'm new to python and I'm trying to learn it using Google Colab I'm trying to open a CSV file, but I just can't do it.

import csv
open(r'C:\Users\User\Desktop\username.csv')

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-30-d948a291431c> in <module>()
      1 import csv
----> 2 open(r'C:\Users\User\Desktop\username.csv')

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\Desktop\\username.csv'

I've already searched for similar questions, mostly of them sugest the problem is the (r'C:\completelocalfile), but I already tried, as you can see on my code, however it's not working for me. Any sugestions?

Upvotes: 4

Views: 28576

Answers (1)

SilentCloud
SilentCloud

Reputation: 1985

Does this help? Basically, Google Colab cannot access your local machine files.

As a workaround, I would suggest to upload file on you drive, mount your drive in Colab, and then load the file from there.

The snippet to mount drive is the following:

from google.colab import drive
drive.mount('/content/drive', force_remount=True)

After that, you can upload the file manually and finally you load the file with the following command:

filename = r'/content/drive/MyDrive/pathtoyourfile'
import csv
open(filename)

Upvotes: 3

Related Questions