A. *_*don 3 python bash jupyter-notebook
我使用的是装有 Windows 7 的 PC 和来自 Anaconda3 2.3.0 版的 Python 3.4 Jupyter 笔记本。
我正在尝试bash从 Jupyter 笔记本运行 cell magic命令,但遇到了我想其他人也会遇到的问题。
从我在教程中看到的内容来看,它应该很简单......
%%bash
pwd
Run Code Online (Sandbox Code Playgroud)
当我尝试此操作时,出现错误“找不到程序:'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> .
Run Code Online (Sandbox Code Playgroud)
但是,如果我在命令上方放置一个 return ,它似乎将单元格解释为 python 并给出“名称 'ls' 未定义”错误。
如果我尝试调用bashline magic 命令%bash,则会出现以下错误:
'ERROR: Line magic function `%bash` not found (But cell magic `%%bash` exists, did you mean that instead?)'.
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助。
您是否尝试过错误消息所说的尝试?
即 '%%bash' 而不是 '%bash'
该页面似乎表明您需要两个百分号来使用 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.
Run Code Online (Sandbox Code Playgroud)
以下命令有效:
%%cmd
dir
Run Code Online (Sandbox Code Playgroud)
buruzaemon 钉了它。