过去几个月来,我一直在使用Google Colab,在连接驱动器和使用!
键入shell命令方面没有遇到问题。但是今天,突然发生了一个错误,我找不到任何解决方法。 Colab似乎不可思议地无法浏览目录。对于诸如cd,pwd,mkdir等目录的所有bash命令,我都会收到错误消息。
即使在关闭后,重新打开笔记本电脑并重新启动运行系统,也仅运行单行代码:
!pwd
我收到此错误:
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
控制台通常会打印/content
。
我已经能够通过创建Notebook的副本来绕过该问题,但是我仍然想问这个问题,因为在Google,Stackoverflow和超级用户中查看后,我没有找到紧密相关的单个线程我的问题。我也徒劳地查看了Colab的文档。因此,我认为打开一个讨论新问题的话题将对整个社区有益。
有人遇到过这个问题,知道如何解决吗?
感谢大家:)
答案 0 :(得分:2)
在Colab实例中不会丢失变量,
使用os库更改目录。
import os
path = "/content" # /content is pretty much the root. you can choose other path in your colab workspace
os.chdir(path)
答案 1 :(得分:1)
我也遇到这个问题。
当我训练模块时,它突然向我显示警告,此后我的colab仍在运行,但程序似乎未运行。我关闭了网页,然后再次打开,它像您一样显示警告,但是我的协作室看起来又可以工作了。它仍然可以从Google云端硬盘加载模块文件。
答案 2 :(得分:0)
我也有这个问题。
原因:我想这是因为该目录(您所在的目录)被意外删除了。我从here获得了这一意见。然后cd
和pwd
将不再起作用。现在我仍然可以使用python,我尝试使用
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)
解决方案:运行上面的python函数:os.exit(00)
以重新启动colab内核,旨在返回有效路径。
ps: !reboot
被colab禁止
答案 3 :(得分:0)
我遇到了类似的问题。这是快速解决方案:
现在,您将可以在colab单元中使用shell命令。