在Jupyter Notebook中使用bash命令 [英] using bash commands in jupyter notebook

查看:758
本文介绍了在Jupyter Notebook中使用bash命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有在jupyter笔记本上使用bash.对于某些项目,我需要将bash与python一起使用,但这给了我错误.我还安装了bash内核.

I never used bash with jupyter notebook. For some project, I need to use bash with python but it's giving me errors. I have installed bash kernel also.

PATH="/Downloads/dogscats/"
!ls {PATH}

'ls'不被识别为内部或外部命令, 可操作的程序或批处理文件.

'ls' is not recognized as an internal or external command, operable program or batch file.

推荐答案

只要从兼容bash的命令行(例如Git Bash)启动Jupyter,即使在Windows系统上,也可以在Jupyter Notebook中使用bash命令. (MingW64).如OP的代码示例所示,bash命令必须以感叹号(!)开头.

It is possible to use bash commands in Jupyter Notebook, even on Windows systems, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64). As shown in the OP's code example, the bash command must be prepended by an exclamation mark (!).

但是,真正的钥匙是从 Git Bash 或可能是

The real key, however, is launching from Git Bash or possibly Ubuntu on Windows .

我正在运行Windows 10 Pro,并且通过Anaconda安装了Python,当我通过Git Bash启动Jupyter时,以下代码可以工作,但是从Anaconda提示符下启动时,以下代码无法工作.

I'm running windows 10 Pro with Python installed via Anaconda, and the following code works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt.

>>> !ls
database.sqlite
Weather Data Clustering using k-Means.ipynb

>>>!pip show lxml | grep Version
Version: 4.1.0

这篇关于在Jupyter Notebook中使用bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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