Search code examples
pythongoogle-colaboratoryworking-directorychdirgetcwd

How do I change my working directory in a proper manner?


I'm working in Google Colab and I'm trying to change to working directory to my desktop (desktop = bureaublad in dutch thats why you see 'bureaublad in my path). However, changing the working directory keeps giving me the error that such a directory doesn't exist. I just copied the path so everything should exist! See my code here:

Code:

import os
print(os.getcwd())
os.listdir()

Output:

/content
['.config', 'sample_data']

Code:

os.chdir(r'C:\Users\emile\OneDrive\Bureaublad\Completed Communications Transcriptions')

Output:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-29-c4d97f3ec347> in <module>()
----> 1 os.chdir(r'C:\Users\emile\OneDrive\Bureaublad\Completed Communications Transcriptions')

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\emile\\OneDrive\\Bureaublad\\Completed Communications Transcriptions'

What did I do wrong?


Solution

  • You need to be connected to a local runtime by hosting a jupyter notebook server and then enter port number then you can succesfully connect if you are connected to a hosted runtime you can only connect to google drive by mounting it.

    More information can be found here- Can you run Google Colab on your local computer?