【问题标题】:dask worker cannot import moduledask worker 无法导入模块
【发布时间】:2019-05-10 13:53:58
【问题描述】:

我正在运行一个 dask 集群和一个 worker w。使用 CLI 实用程序的 16 个内核。 总的来说,它似乎工作得很好。 但是,由于某种原因,它不会在 cwd 中导入模块。 我尝试从我的笔记本实例中运行以下命令:

def tstimp():
  import os
  return os.listdir()
c.run(tstimp)

我得到以下输出:

{'tcp://192.168.1.90:35885': ['class_positions.csv',
'.gitignore',
'README.md',
'fullrun.ipynb',
'.git',
'rf.py',
'__pycache__',
'dask-worker-space',
'utils.py',
'.ipynb_checkpoints']}

请注意,此处列出了模块 rf.py。 因此应该可以在worker中导入它,但是当我运行以下代码时:

def tstimp():
  import rf
  return 42
c.run(tstimp)

我收到此错误:ModuleNotFoundError: No module named 'rf'

为什么会出现这个错误?

【问题讨论】:

    标签: python-3.x parallel-processing cluster-computing dask dask-distributed


    【解决方案1】:

    当前目录似乎没有添加到工人的 python 路径中。 您应该可以通过将其添加到路径来解决此问题。

    def tstimp():
      import sys
      sys.path.append('.')
      import rf
      return 42
    c.run(tstimp)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      • 2021-11-09
      • 2017-11-11
      • 2021-07-27
      • 2019-06-13
      相关资源
      最近更新 更多