6

I've been using Google Colab for the past months without issues connecting to drive and typing shell commands with !. However today, an error suddenly occurred and I can't find anything to solve it. Colab seems to magically not be able to navigate through directories. I get an error for any bash commands for directories like cd, pwd, mkdir, etc..

Even after closing, reopening the notebook and restarting Runtime, and only running the single line of code :

!pwd

I get this error :

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Transport endpoint is not connected
pwd: error retrieving current directory: getcwd: cannot access parent directories: Transport endpoint is not connected

whereas you normally would get /content printed by the console.

I've been able to bypass the problem by creating a copy of the Notebook, but I still wanted to ask this question, since after looking in Google, Stackoverflow, Super User, I didn't find a single thread closely related to my issue. I've also looked in Colab's documentation in vain. So I thought it would benefit the community as a whole in the future to open a thread talking about a new issue.

Has anybody encountered the issue and know how to fix this ?

Thanks to all of you :)

Atralb
  • 505
  • 5
  • 13
  • What's the output of `%pwd`? Perhaps you Drive FUSE mount has become stuck, in which case resetting your backend using Runtime -> Reset all runtimes will reset everything. – Bob Smith Jan 26 '19 at 21:08
  • @BobSmith I thought about testing that but didn't want to since I have other notebooks running for the moment. But if it is the whole backend why would the issue only be on some notebooks and not a new one I start then ? – Atralb Jan 26 '19 at 21:19

4 Answers4

15

I faced a similar problem. Here's a quick fix to this:

  1. Go to Colab
  2. Click on Runtime
  3. Finally, click on restart runtime.(Caution: Your local variables will be lost)

Now, you'll be able to use shell commands in the colab cell.

Harshit Singh
  • 459
  • 4
  • 15
4

Without losing your variables in the Colab instance,

Use os library to change directory.

import os
path = "/content" # /content is pretty much the root. you can choose other path in your colab workspace
os.chdir(path)
  • 2
    This solution works and doesn't require restarting the runtime (and losing all data). Was able to save 1 GB of data generated after 9 hours thanks to this. +1 – aneroid Dec 03 '20 at 21:36
1

I also had this problem.

Reason: I guess it's because that the directory (where you are in) was accidentally deleted. I got this opinion from here. Then cd and pwd won't work anymore. Now that I can still use python, I tried to use

import os
# I tried to recreate the directory, it was created successfully but I still can't use the `cd` or `pwd` commands.
os.makedir('/root/the_directory_deleted') 
# then I tried to restart the kernel of colab to come back to the original path. it works!!!
os._exit(00)

Solution: run the python function above: os.exit(00) to restart the kernel of colab aiming to back to a valid path.

ps: !reboot was forbidden by colab

Avery
  • 2,035
  • 4
  • 33
  • 32
poorguy
  • 79
  • 1
  • 3
1

I also meet this problem.

When I training module it suddenly show me a warning, after that my colab still running but the program seems not run. And I close the web page then I open it again, it show me the warning like you, but my colab looks work again. It still can load module files from Google Drive.

Sts
  • 11
  • 1
  • Can you please clarify how your answer here answers OP's question *Has anybody encountered the issue and know how to fix this?* – I mean, what's your fix for OP's problem? – Ivo Mori Aug 29 '20 at 14:04