代码之家  ›  专栏  ›  技术社区  ›  Brian

需要整数(get type str):使用ipyparallel和jupyter

  •  2
  • Brian  · 技术社区  · 8 年前

    我正在努力让ipyparallel工作。我正在跟踪 Getting Stared guide 但基本功能在我的机器上不起作用。

    我从命令行启动集群

    ipcluster start -n 4
    

    然后我运行脚本:

     import ipyparallel as ipp
     c=ipp.Client()
     print(c[:].apply_sync(lambda : "Hello, World"))
    

    在Python3中,它可以按预期工作,但在Python2中运行时却不能。我得到错误:

    TypeError: an integer is required (got type str)
    

    此外,当我在Jupyter笔记本中使用python 2和python 3内核运行该代码段时,我得到了相同的错误。

    知道我为什么会犯这个错误吗?谢谢


    编辑:

    jupyter中的总错误为:

    Traceback (most recent call last)~/.local/lib/python3.5/site-packages/ipyparallel/serialize/serialize.py in unpack_apply_message(bufs, g, copy)
        185     assert len(bufs) >= 2, "not enough buffers!"
        186     pf = buffer_to_bytes_py2(bufs.pop(0))
    --> 187     f = uncan(pickle.loads(pf), g)
        188     pinfo = buffer_to_bytes_py2(bufs.pop(0))
        189     info = pickle.loads(pinfo)
    ~/.local/lib/python3.5/site-packages/ipyparallel/serialize/codeutil.py in code_ctor(*args)
         22 
         23 def code_ctor(*args):
    ---> 24     return types.CodeType(*args)
         25 
         26 def reduce_code(co):
    TypeError: an integer is required (got type str)
    

    我正在使用Python3.5.2和Python2.7.12以及ipyparallel v6.0.2。我发现ipyparallel v6不需要>Python3,虽然我在 docs ,所以我很高兴这只适用于Python3。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Brian    8 年前

    这里的问题是我没有在jupyter中启用集群。在候机楼,我跑了

    sudo ipcluster nbextension enable
    

    在同一终端打开jupyter笔记本

    jupyter notebook
    

    然后它成功了。

    注意:您可能首先需要

    pip install notebook ipyparallel
    

    另请参见 this page 用于使用 ipcluster 在jupyter。