如何在Google Colab中运行shell(终端)? [英] How can I run shell (terminal) in Google Colab?

查看:2465
本文介绍了如何在Google Colab中运行shell(终端)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以调用!ls 来发出 ls 命令来shell。



但是我想要历史记录或制表符补全之类的功能。



是否可以在Google Colab中这样做?

解决方案

您可以使用受 google.colab.kernel.invokeFunction 支持的jQuery Terminal Emulator p>

这是一个


更新(7/2020)


我已将@Anant的答案添加到我的库中。现在,您可以轻松运行控制台,只需

 !pip从kora导入控制台安装kora 

console.start()#然后点击链接


I know that I can call !ls to issue ls command to shell.

But I want features like history or tab-completion.

Is it possible to do so in Google Colab?

解决方案

You can use jQuery Terminal Emulator backed with google.colab.kernel.invokeFunction

Here's an example notebook.

The key part is here, where you back it with shell function.

def shell(command):
  return JSON([getoutput(command)])
output.register_callback('shell', shell)

And here's how you use invokeFunction:

try {
    let res = await google.colab.kernel.invokeFunction('shell', [command])
    let out = res.data['application/json'][0]
    this.echo(new String(out))
} catch(e) {
    this.error(new String(e));
}

Here's a screenshot.

Update (7/2020)

I have taken @Anant's answer and add it into my library. Now you can run console easily with just

!pip install kora
from kora import console
console.start()  # and click link

这篇关于如何在Google Colab中运行shell(终端)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆