简体   繁体   English

如何从用户定义的包,Python导入ipyparallel函数

[英]How to import ipyparallel function from user defined package, Python

I have a python script that contains a number of user defined functions that I have set up a as package locally. 我有一个python脚本,其中包含许多用户定义的函数,这些函数已在本地设置为as包。 I can run all of the functions in the input_processing.py script except for the one that I intend to run in parallel. 我可以运行input_processing.py脚本中的所有功能,但我打算并行运行的功能除外。

Here is the code that imports the package... 这是导入包的代码...

import attrition25.input_processing as attrition

I get this error... 我收到此错误...

NameError: name 'dview' is not defined

This is what the function looks like in input.processing.py... 这就是input.processing.py ...中的函数外观

@dview.parallel(block=True)
def get_dmat_elements(a, b, c):
    d = a + b + c
    return(d)

I tried sync_imports() and looked at the @interactive decorator, but I couldn't get anywhere. 我尝试了sync_imports()并查看了@interactive装饰器,但我什么也没找到。 Any help would be appreciated. 任何帮助,将不胜感激。

Although I don't completely get the scoping, to get the function to work, I had to add this to the beginning of the input_processing.py script... 尽管我没有完全了解范围,但为了使函数正常工作,我不得不将其添加到input_processing.py脚本的开头...

import ipyparallel as ipp
# Create directView Instance for Parallel Processing
c = ipp.Client()
dview = c[:] # use all engines

I have the same exact block of code in the Jupyter Notebook where I am testing, but that did not work. 我在进行测试的Jupyter Notebook中具有完全相同的代码块,但这没有用。

Hopefully this helps someone out there. 希望这可以帮助某个人。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将用户定义的类从包导入到 Jupyter Notebook - How to import a user defined class from a Package to a Jupyter Notebook Python:如何从 package 中导入 function,这取决于 ZEFE8B70A8E6034A787 中的其他功能? - Python: How to import a function from a package that depends on other functions in that package? 软件包的Python导入功能 - Python import function from package Python:如何从任何位置导入用户定义的包? - Python : How to import user defined packages from any location? Python 进口 function 与 package - Python import function with package Python如何在内部区分“来自模块导入功能”和“来自模块导入功能” - How does Python internally distinguish “from package import module” between “from module import function” 如何从另一个目录导入 python package? - How to Import python package from another directory? 如何在python上自行添加用户定义的函数? - How to add a user defined function by itself on python? How to import a function from an R package as if it was native Python function and use all its outputs? - How to import a function from an R package as if it was native Python function and use all its outputs? 如何在cygwin中导入用户定义的python模块? - How to import user-defined python modules in cygwin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM