经过长时间的搜索,我还没有找到横跨多个文件的Dataflow / Beam管道的示例。 Beam文档可以使用suggest a file structure(在“多个文件依赖项”下),但是他们给出的Juliaset示例实际上具有a single code/source文件(以及调用该文件的main file)。基于Juliaset示例,我需要类似的文件结构:
juliaset/__init__.py
juliaset/juliaset.py # actual code
juliaset/some_conf.py
__init__.py
juliaset_main.py
setup.py
现在我想从
import .some_conf
中获取juliaset/juliaset.py
,它在本地运行时可以工作,但是在Dataflow上运行时却给我一个错误INFO:root:2017-12-15T17:34:09.333Z: JOB_MESSAGE_ERROR: (8cdf3e226105b90a): Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/dataflow_worker/batchworker.py", line 706, in run
self._load_main_session(self.local_staging_directory)
File "/usr/local/lib/python2.7/dist-packages/dataflow_worker/batchworker.py", line 446, in _load_main_session
pickler.load_session(session_file)
File "/usr/local/lib/python2.7/dist-packages/apache_beam/internal/pickler.py", line 247, in load_session
return dill.load_session(file_path)
File "/usr/local/lib/python2.7/dist-packages/dill/dill.py", line 363, in load_session
module = unpickler.load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 1133, in load_reduce
value = func(*args)
File "/usr/local/lib/python2.7/dist-packages/dill/dill.py", line 767, in _import_module
return getattr(__import__(module, None, None, [obj]), obj)
ImportError: No module named package_name.juliaset.some_conf
一个完整的工作示例将不胜感激!
最佳答案
您可以验证您的setup.py
包含如下结构吗:
import setuptools
setuptools.setup(
name='My Project',
version='1.0',
install_requires=[],
packages=setuptools.find_packages(),
)
像
from juliaset.juliaset import SomeClass
一样导入模块当您调用Python脚本时,请使用
python -m juliaset_main
(不带.py)不知道您是否已经尝试过此操作,但是请确定。