我一直在玩IPython.parallel我想使用我自己的一些自定义模块,但未能如the cookbook使用dview.sync_imports()
中所述做到这一点。唯一对我有用的是
def my_parallel_func(args):
import sys
sys.path.append('/path/to/my/module')
import my_module
#and all the rest
然后主要是为了
^{pr2}$我认为正确的方法应该是
with dview.sync_imports():
import sys
sys.path.append('/path/to/my/module')
import my_module
但这会抛出一个错误,说明没有名为my_module
的模块。在
那么,使用dview.sync_imports()
的正确方法是什么??在
问题是您只在运行客户端的本地进程中更改}的远程进程中更改{}。在
PYTHONPATH
,而不是在运行{如果运行下一个和平代码,您可以观察到这种行为:
基本上,所有要与
sync_imports
一起使用的模块必须已经在PYTHONPATH
中。在如果它不在
PYTHONPATH
中,则必须将其添加到远程执行的函数中的路径中,然后在函数中导入模块。在相关问题 更多 >
编程相关推荐