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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37335201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:39:08  来源:igfitidea点击:

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

pythonbashjupyter-notebook

提问by A. Gordon

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

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

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

我正在尝试bash从 Jupyter 笔记本运行 cell magic命令,但遇到了我想其他人也会遇到的问题。

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 bashcommands. I have also tried !bash and that has not worked.

当我尝试此操作时,出现错误“找不到程序:'bash'”。对于其他bash命令也是如此。我也试过 !bash,但没有奏效。

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.

我能够运行不需要参数的 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>          .

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.

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

If I attempt to call the bashline magic command %bashI get the below error:

如果我尝试调用bashline magic 命令,%bash我会收到以下错误:

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

Thanks in advance for any help.

在此先感谢您的帮助。

回答by wonkybadonk

Did you try what the error message said to try?

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

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

即 '%%bash' 而不是 '%bash'

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

该页面似乎表明您需要两个百分号来使用 bash 脚本魔法。

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

编辑。量身定制的答案不再是特定的错误消息。当我运行 %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.

The following command works:

以下命令有效:

%%cmd
dir

buruzaemon nailed it.

buruzaemon 钉了它。