IPython Notebook %%bash Magic Error

我只是一个虾纸丫 提交于 2019-12-08 03:15:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16281910/ipython-notebook-bash-magic-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!