简体   繁体   English

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

[英]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. 我正在使用带有Windows 7的PC和来自Anaconda3版本2.3.0的Python 3.4 Jupyter笔记本。

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. 我正试图从Jupyter笔记本运行cell magic bash命令,并且遇到了我想象其他人也会遇到的问题。

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'". 当我尝试这个时,我收到错误“找不到程序:'bash'”。 This is true for other bash commands. 其他bash命令也是如此。 I have also tried !bash and that has not worked. 我也试过了!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. 但是,如果我在命令之上放置一个返回值,它似乎将单元格解释为python并给出“name'ls'未定义”错误。

If I attempt to call the bash line magic command %bash I get the below error: 如果我尝试调用bash line 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. 在此先感谢您的帮助。

Did you try what the error message said to try? 您是否尝试过错误消息所说的尝试?

ie '%%bash' instead of '%bash' 即'%% bash'而不是'%bash'

This page seems 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. 量身定制的答案不再是特定的errawr消息。 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钉了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM