Reputation: 399
I am getting this error everytime running python code on local data from my drive I am using the code below to import the data from my drive
from google.colab import drive
drive.mount('/content/drive')
Upvotes: 28
Views: 204409
Reputation: 577
I came over the issue when I used regex as follows. You may also want to try it.
import os
os.chdir(r"/content/drive/My Drive")
Note the position of r, for regex
Upvotes: 1
Reputation: 1
to run a python file in the Google Drive;
!python3 /content/drive/My\ Drive/data/file.py
Upvotes: 0
Reputation: 61
For troubleshooting above and to find and load local data files in Google Colab:
Reference: Load local data files to Colaboratory
Upvotes: 1
Reputation: 11
I had the same issue, for me it was that "drive" needs to be spelled with an r as "driver". "My Drive" including the space worked for me as well.
os.chdir('/content/driver/My Drive/*filename*/')
Upvotes: 0
Reputation: 981
os.chdir('/content/drive/MyDrive')
ls
to check whether the file exists
try to avoid spaces when you are creating new directories inside the drive cos it can lead to compile-time errors
If you just want to mount your drive to the colab you can do that without any code using the web IDE
Upvotes: 1
Reputation: 166
google has changed to Mydrive and deleted space. so no "My Drive" but "MyDrive os.chdir('/content/gdrive/MyDrive/iss/vse/data/')
Upvotes: 2
Reputation: 4179
First, check the path. Make sure the file exists in the right path.
Simple. Just use terminal code like this example of mine:
! ls /content/drive/My\ Drive/data/sahamyab
colabs respons:
data.jl sahamyab.zip tweets.json
If your file is not on that path, then you are in the wrong way. Otherwise, after you see that the file exists, just open it like this:
open("/content/drive/My Drive/data/sahamyab/tweets.json")
WARNING: look at paths carefully. The first one has My\ Drive
and the second My Drive
. because the first one is on the terminal path and space is \
but the second one is in the python path.
Upvotes: 8
Reputation: 434
Check if your file exists in this "/content/drive/" location
import os
os.chdir("/content/drive/")
!ls
Most likely it would be under 'My Drive'
import os
os.chdir("/content/drive/My Drive")
!ls
Upvotes: 29