agconti
agconti

Reputation: 18123

IPython Notebook %%bash Magic Error

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.

Upvotes: 3

Views: 8913

Answers (1)

Chronial
Chronial

Reputation: 70763

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.

Upvotes: 8

Related Questions