在过去的几个月里,我一直在使用谷歌Colab,没有遇到连接驱动器和使用!
输入外壳命令的问题。然而,今天突然发生了一个错误,我找不到任何东西来解决它。Colab似乎神奇地不能在目录中导航。对于cd、pwd、mkdir等目录的任何bash命令,我都会收到一个错误。
即使在关闭后,重新打开notebook并重新启动Runtime,并且只运行一行代码:
!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,Super User中查找后,我没有找到一个与我的问题密切相关的帖子。我还查看了Colab的文档,但没有找到。因此,我认为,在未来,打开一条讨论新问题的帖子,对整个社区都有好处。
有没有人遇到过这个问题并知道如何解决这个问题?
感谢你们所有人:)
发布于 2019-06-12 17:59:05
我也遇到过类似的问题。这里有一个快速解决方案:
。(注意:您的本地变量将丢失)
现在,您将能够在colab单元中使用shell命令。
发布于 2020-08-14 20:47:08
在不丢失Colab实例中的变量的情况下使用
使用os库更改目录。
import os
path = "/content" # /content is pretty much the root. you can choose other path in your colab workspace
os.chdir(path)
发布于 2019-04-30 18:41:03
我也有这个问题。
原因:我猜是因为你所在的目录被意外删除了。我是从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 Solution:运行上面的os.exit(00)
函数重启内核,目标是回到有效路径。
ps: !reboot
被colab禁止
https://stackoverflow.com/questions/54382643
复制相似问题