在魔术单元格中使用bash命令时,请使用呼叫Processerror



我在木星笔记本中使用了以下代码。

%%bash -s "$store_path" "$store_file"
! echo a = $1, b = $2
! cat $1 | awk '{ print length, $0 }' | sort -n -s | cut -d ' ' -f 2- | awk '!a[$0]++' > $2

这以前用来完美地工作,并且经过了很长的差距,我试图使用此代码。它显示了下面的问题,我不知道。

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-30-1e2db86b01e6> in <module>
----> 1 get_ipython().run_cell_magic('bash', '-s "$store_path" "$store_file"', "! echo a = $1, b = $2n! cat $1 | awk '{ print length, $0 }' | sort -n -s | cut -d ' ' -f 2- | awk '!a[$0]++' > $2n")
~/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2350             with self.builtin_trap:
   2351                 args = (magic_arg_s, cell)
-> 2352                 result = fn(*args, **kwargs)
   2353             return result
   2354 
~/.local/lib/python3.6/site-packages/IPython/core/magics/script.py in named_script_magic(line, cell)
    140             else:
    141                 line = script
--> 142             return self.shebang(line, cell)
    143 
    144         # write a basic docstring:
</home/ambijat/.local/lib/python3.6/site-packages/decorator.py:decorator-gen-110> in shebang(self, line, cell)
~/.local/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):
~/.local/lib/python3.6/site-packages/IPython/core/magics/script.py in shebang(self, line, cell)
    243             sys.stderr.flush()
    244         if args.raise_error and p.returncode!=0:
--> 245             raise CalledProcessError(p.returncode, cell, output=out, stderr=err)
    246 
    247     def _run_script(self, p, cell, to_close):
CalledProcessError: Command 'b"! echo a = $1, b = $2n! cat $1 | awk '{ print length, $0 }' | sort -n -s | cut -d ' ' -f 2- | awk '!a[$0]++' > $2n"' returned non-zero exit status 1.

我试图通过使用一行作为import subprocess来操纵,但它不会成功。我尝试使用的另一件事是使用%代替%%,但这也行不通。需要帮助。

一旦%%在顶部,则在连续的行中不需要!。另外,从关于旧代码的记忆中,也应避免使用#在魔术单元内插入顶部的注释,因为它也会产生一些错误。

相关内容

最新更新