Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter notebook - Couldn't find program: 'bash'

I'm using a PC with Windows 7 and a Python 3.4 Jupyter notebook from Anaconda3 version 2.3.0.

I'm attempting to run the cell magic bash command from a Jupyter notebook and am having problems that I imagine others will encounter as well.

From what I've seen in tutorials, it should be as simple as...

%%bash
pwd

When I attempt this, I get the error "Couldn't find program: 'bash'". This is true for other bash commands. I have also tried !bash and that has not worked.

A few strange observations that may help:

I am able to run bash commands that don't require parameters as long as they are the first line in the cell.

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>          .

However if I put a return above the command, it seems to interpret the cell as python and gives the "name 'ls' is not defined" error.

If I attempt to call the bash line magic command %bash I get the below error:

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

Thanks in advance for any help.

like image 560
A. Gordon Avatar asked Sep 18 '25 23:09

A. Gordon


1 Answers

Did you try what the error message said to try?

i.e. '%%bash' instead of '%bash'

This page seems to indicate that you're going to want two percent signs to utilize the bash script magic.

Edit. Tailored answer to no longer be to specific errawr message. When I run %lsmagic I get the following:

%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.

The following command works:

%%cmd
dir

buruzaemon nailed it.

like image 142
wonkybadonk Avatar answered Sep 20 '25 14:09

wonkybadonk