Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 712
lipao255 Avatar asked Oct 22 '25 12:10

lipao255


1 Answers

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)
like image 105
SilentCloud Avatar answered Oct 24 '25 02:10

SilentCloud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!