Jupyter 笔记本 - 找不到程序:'bash'
Jupyter notebook - Couldn't find program: 'bash'
我使用的是装有 Windows 7 和 Python 3.4 Jupyter notebook 来自 Anaconda3 2.3.0 版的电脑。
我正在尝试从 Jupyter notebook 运行 cell magic bash
命令,我遇到了我想其他人也会遇到的问题。
根据我在教程中看到的内容,它应该很简单...
%%bash
pwd
当我尝试这样做时,出现错误 "Couldn't find program: 'bash'"。对于其他 bash
命令也是如此。我也试过 !bash 但没用。
一些可能有帮助的奇怪观察:
我能够 运行 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> .
但是,如果我在命令上方放置 return,它似乎会将单元格解释为 python 并给出 "name 'ls' is not defined" 错误。
如果我尝试调用 bash
行魔术命令 %bash
我会收到以下错误:
'ERROR: Line magic function `%bash` not found (But cell magic `%%bash` exists, did you mean that instead?)'.
在此先感谢您的帮助。
您是否按照错误信息所说的进行了尝试?
即'%%bash' 而不是 '%bash'
This page 似乎表明您需要两个百分号来使用 bash 脚本魔法。
编辑。不再针对特定错误消息的定制答案。当我 运行 %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.
以下命令有效:
%%cmd
dir
buruzaemon 做到了。
我使用的是装有 Windows 7 和 Python 3.4 Jupyter notebook 来自 Anaconda3 2.3.0 版的电脑。
我正在尝试从 Jupyter notebook 运行 cell magic bash
命令,我遇到了我想其他人也会遇到的问题。
根据我在教程中看到的内容,它应该很简单...
%%bash
pwd
当我尝试这样做时,出现错误 "Couldn't find program: 'bash'"。对于其他 bash
命令也是如此。我也试过 !bash 但没用。
一些可能有帮助的奇怪观察:
我能够 运行 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> .
但是,如果我在命令上方放置 return,它似乎会将单元格解释为 python 并给出 "name 'ls' is not defined" 错误。
如果我尝试调用 bash
行魔术命令 %bash
我会收到以下错误:
'ERROR: Line magic function `%bash` not found (But cell magic `%%bash` exists, did you mean that instead?)'.
在此先感谢您的帮助。
您是否按照错误信息所说的进行了尝试?
即'%%bash' 而不是 '%bash'
This page 似乎表明您需要两个百分号来使用 bash 脚本魔法。
编辑。不再针对特定错误消息的定制答案。当我 运行 %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.
以下命令有效:
%%cmd
dir
buruzaemon 做到了。