3

I'm trying to follow a version control tutorial in an IPython Notebook by Fernando Perez, a static version of which can be found here.

He uses the %%bash magic extensively, but When I use it I get the following error:

ERROR: Cell magic function %%bash not found.

Even though when I use the !git command; everything works fine.

Specifics:

C:\Python27\Scripts;
C:\Program Files (x86)\Git\cmd;
C:\Program Files (x86)\Git\bin\;

Are all added to my system path.

I'm running the 0.13.2 version of IPython installed via a 64 bit windows binary from Christoph Gohlke at his site.

Running Git 1.8.0

Related:

Magic function `bash ` not found

His solution is to update his IPython version. My Version is updated.

Community
  • 1
  • 1
agconti
  • 17,780
  • 15
  • 80
  • 114

1 Answers1

8

The reason that is not working is that you are running on windows. Windows does not have bash but cmd. In line with that is that ipython does not have %%bash magic, but %%cmd magic. You could try rewriting his commands to %%cmd, but beware that cmd is different from bash and so his commands might not work quite right.

To run this notebook on windows, you need to install cygwin and run ipython from there. You do not need to install ipython in cygwin – running the windows ipython is just fine, but you have to run it from a cygwin shell.


Update: After some research, I found out what makes the cygwin shell special: It puts bash in its PATH. So you don’t need cygwin after all. Having git installed is enough. Just create a batch file named notebook.bat or something with the following content:

@echo off
set PATH=%PATH%;C:\Program Files\Git\bin
ipython notebook

When you run your notebook using this batch file, the %%bash command will be available and working.

Chronial
  • 66,706
  • 14
  • 93
  • 99
  • Thanks for answering my question. I thought the %%bash command related to Git Bash. Now I feel silly. Like I listed above, I can use the '!' command to execute git on the command line in IPython, but when I use the same expression ie. '%%cmd git status' there is no response. Also why would I have to launch the notebook from the cygwin dir? would that make the '%%bash' style magic work? – agconti Apr 29 '13 at 17:38
  • Running `%%cmd \n git status` should work (note the newline!). Also I said nothing about the cygwin **dir** – I was talking about the cygwin **shell** ;) – Chronial Apr 29 '13 at 17:45
  • ok, running ipython from the git shell is not enough. But to clarify: if you run ipython from a cygwin shell, the `%%bash` magic works – Chronial Apr 29 '13 at 18:05
  • Thanks for the cygwin shell %%bash clarification. '%%cmd \n git status' still dosent work for me where !git status works fine. I'm running these in an IPython Notebook so the new line was implied in the notebook when I wrote %%cmd git status'. I'm looking to use the %%cmd / %%bash syntax because I want to handle all of my version control from the Notebook to back up my research projects. As my use of git commands becomes more complicated the use of '!' really starts to drag and the %%cmd magic is more and more necessary. Also the magic printing is identical to what you would get in git. – agconti Apr 29 '13 at 18:29
  • What does `%%cmd \n git status` output for you? And you need to have a newline at the end of this, so: `%%cmd \n git status \n` – Chronial Apr 29 '13 at 19:00
  • The response is identical to just running %%cmd. here it is: ' Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation. All rights reserved. C:\Users\[my user id]>' – agconti Apr 30 '13 at 02:39
  • That is very weird – you could try adding more newlines at the end ^^. Otherwise try running form cygwin. cmd is crap for stuff like this anyways. – Chronial Apr 30 '13 at 03:08
  • I seem to have better bash compatibility when I install 32 bit git with defaults setups on my windows PC – Manuel Hernandez Jul 03 '16 at 14:01