Kor*_*ich 23 shell terminal command-line google-colaboratory
我知道我可以调用向 shell!ls发出ls命令。
但我想要历史记录或制表符完成等功能。
在 Google Colab 中可以这样做吗?
pop*_*rny 39
我刚刚写了一个在colab中运行xterm的工具。只需三行代码,您就可以获得一个交互式终端。
\n!pip install colab-xterm\n%load_ext colabxterm\n%xterm\nRun Code Online (Sandbox Code Playgroud)\n如果您觉得有用,请为该项目star。\xe2\xad\x90\xef\xb8\x8f
\nKor*_*ich 37
您可以使用支持的 jQuery Terminal Emulator google.colab.kernel.invokeFunction
这是一个示例笔记本。
关键部分在这里,你用 shell 函数支持它。
def shell(command):
return JSON([getoutput(command)])
output.register_callback('shell', shell)
Run Code Online (Sandbox Code Playgroud)
这是你如何使用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));
}
Run Code Online (Sandbox Code Playgroud)
这是一个屏幕截图。
我已经接受了@Anant 的回答并将其添加到我的图书馆中。现在您可以轻松地运行控制台
!pip install kora
from kora import console
console.start() # and click link
Run Code Online (Sandbox Code Playgroud)
如果您订阅了 Colab Pro,则终端现在可用。只需单击左侧窗格中的“终端”图标。
Raj*_*aju 12
只需键入以下内容。它将产生一个 bash 会话。
!bash
Run Code Online (Sandbox Code Playgroud)
Kul*_*dhu 11
https://github.com/singhsidhukuldeep/Google-Colab-Shell
pip install google-colab-shell
Run Code Online (Sandbox Code Playgroud)
# import the module once
from google_colab_shell import getshell
Run Code Online (Sandbox Code Playgroud)
## Anytime you want to open a terminal
getshell()
getshell(height=400) # custom height of the terminal
Run Code Online (Sandbox Code Playgroud)
重要提示: 确保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)
Run Code Online (Sandbox Code Playgroud)
请贡献:https://github.com/singhsidhukuldeep/Google-Colab-Shell#todo-want-to-contribute
Ana*_*ant 10
最好试试这个——
!curl https://www.teleconsole.com/get.sh | sh
Run Code Online (Sandbox Code Playgroud)
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())
Run Code Online (Sandbox Code Playgroud)
你应该得到类似的输出 -
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
Run Code Online (Sandbox Code Playgroud)
curl https://www.teleconsole.com/get.sh | sh
Run Code Online (Sandbox Code Playgroud)
然后使用以下代码使用您在第 2 步中获得的 Teleconsole Id 加入终端 -
teleconsole join <Teleconsole ID>
Run Code Online (Sandbox Code Playgroud)
这种方法也可以通过一些额外的步骤通过 ssh 进行隧道传输。
| 归档时间: |
|
| 查看次数: |
37469 次 |
| 最近记录: |