Jupyter笔记本 - 找不到程序:'bash'

时间:2016-05-19 22:42:15

标签: python bash jupyter-notebook

我正在使用带有Windows 7的PC和来自Anaconda3版本2.3.0的Python 3.4 Jupyter笔记本。

我正在尝试从Jupyter笔记本运行单元魔术bash命令,并且我遇到了其他人也会遇到的问题。

从我在教程中看到的,它应该像......一样简单。

%%bash
pwd

当我尝试这个时,我收到错误“找不到程序:'bash'”。其他bash命令也是如此。我也试过了!bash而且还没有用。

一些可能有帮助的奇怪观察结果:

我可以运行不需要参数的bash命令,只要它们是单元格中的第一行即可。

In: 
ls    

Out:
Volume in drive D is DATA
Volume Serial Number is XXXX-XXXX

Directory of D:\...

05/19/2016  06:25 PM    <DIR>          .

但是,如果我在命令上方放置一个返回值,它似乎将单元格解释为python并且给出“名称'ls'未定义”错误。

如果我尝试拨打bash行魔术命令%bash,我会收到以下错误:

'ERROR: Line magic function `%bash` not found (But cell magic `%%bash` exists, did you mean that instead?)'.

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您是否尝试过错误消息所说的尝试?

即。 '%% bash'代替'%bash'

This page似乎表明你想要两个百分号来利用bash脚本魔法。

编辑。量身定制的答案不再是特定的errawr消息。当我运行%lsmagic时,我得到以下内容:

%lsmagic

Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cd %clear  %cls  %colors  %config  %connect_info  %copy  %ddir  %debug  
%dhist  %dirs  %doctest_mode  %echo  %ed  %edit  %env  %gui  %hist  
%history  %install_default_config  %install_ext  %install_profiles %killbgscripts  %ldir  
%less  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %macro  %magic  
%matplotlib  %mkdir  %more  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2 
%popd  %pprint  %precision  
%profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx 
%reload_ext  %ren  %rep  %rerun  %reset  %reset_selective  %rmdir  %run  %save  %sc  %set_env  %store  %sx  
%system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%cmd  %%debug  %%file  %%html  %%javascript  
%%latex  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  
%%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

以下命令有效:

%%cmd
dir

buruzaemon钉了它。