我知道我可以调用
但我想要像历史记录或标签补全这样的功能。
在Google Colab中是否可能实现?
!ls
来向shell发出ls
命令。但我想要像历史记录或标签补全这样的功能。
在Google Colab中是否可能实现?
!ls
来向shell发出ls
命令。您可以使用jQuery终端模拟器,支持google.colab.kernel.invokeFunction
这是一个示例笔记本。
关键部分在于在shell函数中支持它。
def shell(command):
return JSON([getoutput(command)])
output.register_callback('shell', shell)
以下是如何使用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));
}
这是一个截图。
我已将@Anant的答案添加到我的库中,现在你可以轻松地使用以下命令运行控制台:
!pip install kora
from kora import console
console.start() # and click link
如果您订阅了Colab Pro,现在可以使用终端。只需单击左侧窗格上的“终端”图标即可。
我刚刚编写了一个工具,在colab中运行xterm。只需要三行代码,你就可以获得一个交互式终端。
!pip install colab-xterm
%load_ext colabxterm
%xterm
如果您觉得它有用,请给这个项目加星。⭐️
只需输入以下内容。它将生成一个bash会话。
!bash
它以密码格式显示命令。如果你使用浏览器开发工具将输入类型从password
更改为text
,会非常有帮助。
https://github.com/singhsidhukuldeep/Google-Colab-Shell
pip install google-colab-shell
# import the module once
from google_colab_shell import getshell
## Anytime you want to open a terminal
getshell()
getshell(height=400) # custom height of the terminal
重要提示:确保 getshell
是单元格中的最后一个命令。
Displays a terminal for Google Colab. <3 Google
Make sure this is the last command in the cell.
Parameters
----------
height : int, default 400
height of the rendered terminal
Returns
-------
IPython.display.HTML
Displays the terminal
Examples
--------
>>> getshell()
>>> getshell(height=400)
请贡献代码:https://github.com/singhsidhukuldeep/Google-Colab-Shell#todo-want-to-contribute
建议尝试以下步骤 -
!curl https://www.teleconsole.com/get.sh | sh
在Colab笔记本上运行以下代码即可使用Teleconsole - import subprocess as sp
process = sp.Popen("teleconsole",shell=True,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE)
for i in range(6):
print(process.stdout.readline().decode())
你应该会得到类似以下的输出 - Starting local SSH server on localhost...
Requesting a disposable SSH proxy on eu.teleconsole.com for root...
Checking status of the SSH tunnel...
Your Teleconsole ID: eu88d75d24084905shgdjhjhfgd1934e55c3786438a3
WebUI for this session:
https://eu.teleconsole.com/s/88d75d24084905shgdjhjhfgd1934e55c3786438a3
curl https://www.teleconsole.com/get.sh | sh
请使用以下代码,使用第2步中获得的Teleconsole Id加入终端。 teleconsole join <Teleconsole ID>
使用一些额外的步骤,也可以通过ssh隧道来实现此方法。
!<cmd>
对你来说不够用? - Charlie Parker