1
是否有可能從谷歌數據流(梁)內得到matplotlib模塊?我有它在我的requirements.txt:如何使用matplotlib模塊中的Apache梁谷歌的數據流亞軍
matplotlib==2.0.2
但仍然得到錯誤:
ImportError: No module named matplotlib
謝謝!
是否有可能從谷歌數據流(梁)內得到matplotlib模塊?我有它在我的requirements.txt:如何使用matplotlib模塊中的Apache梁谷歌的數據流亞軍
matplotlib==2.0.2
但仍然得到錯誤:
ImportError: No module named matplotlib
謝謝!
準備自定義數據流的工人,你應該提供setup.py
文件,安裝所需的軟件包命令。 首先,創建setup.py
文件類似下面的(這是一個普通的setup.py
文件)。 您應該列出REQUIRED_PACKAGES
可變你的包,或只是把pip install matplotlib==2.0.2
在CUSTOM_COMMANDS
像我一樣。
請注意,matplotlib需要一些額外的軟件包/庫被安裝在系統中,所以你需要安裝它們也通過指定他們安裝的命令。此外,如果你想使數據流裏面工作地塊,則需要配置matplotlib後端一個,這是能夠寫入文件輸出(見How can I set the 'backend' in matplotlib in Python?)。
然後,創建setup.py
文件後,只需指定阿帕奇梁管道參數:
import apache_beam as beam
p = beam.Pipeline("DataFlowRunner", argv=[
'--setup_file', './setup.py',
# put other parameters here
])
通用setup.py
文件:
import sys
import os
import logging
import subprocess
import pickle
import setuptools
import distutils
from setuptools.command.install import install as _install
class install(_install): # pylint: disable=invalid-name
def run(self):
self.run_command('CustomCommands')
_install.run(self)
CUSTOM_COMMANDS = [
['pip', 'install', 'matplotlib==2.0.2'],
]
class CustomCommands(setuptools.Command):
"""A setuptools Command class able to run arbitrary commands."""
def initialize_options(self):
pass
def finalize_options(self):
pass
def RunCustomCommand(self, command_list):
logging.info('Running command: %s' % command_list)
p = subprocess.Popen(
command_list,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# Can use communicate(input='y\n'.encode()) if the command run requires
# some confirmation.
stdout_data, _ = p.communicate()
logging.info('Command output: %s' % stdout_data)
if p.returncode != 0:
raise RuntimeError(
'Command %s failed: exit code: %s' % (command_list, p.returncode))
def run(self):
for command in CUSTOM_COMMANDS:
self.RunCustomCommand(command)
REQUIRED_PACKAGES = [
]
setuptools.setup(
name='name',
version='1.0.0',
description='DataFlow worker',
install_requires=REQUIRED_PACKAGES,
packages=setuptools.find_packages(),
cmdclass={
'install': install,
'CustomCommands': CustomCommands,
}
)