将 pyspark 中的 Python 模块传送到其他节点 [英] Shipping Python modules in pyspark to other nodes
问题描述
如何将 C 编译模块(例如,python-Levenshtein)发送到 Spark<中的每个节点/a> 集群?
How can I ship C compiled modules (for example, python-Levenshtein) to each node in a Spark cluster?
我知道我可以使用独立的 Python 脚本(下面的示例代码)在 Spark 中传送 Python 文件:
I know that I can ship Python files in Spark using a standalone Python script (example code below):
from pyspark import SparkContext
sc = SparkContext("local", "App Name", pyFiles=['MyFile.py', 'MyOtherFile.py'])
但是在没有 '.py' 的情况下,我如何发送模块?
But in situations where there is no '.py', how do I ship the module?
推荐答案
如果你可以将你的模块打包成一个 .egg
或 .zip
文件,你应该能够在构建 SparkContext 时将其列在 pyFiles
中(或者您可以稍后通过 sc.addPyFile).
If you can package your module into a .egg
or .zip
file, you should be able to list it in pyFiles
when constructing your SparkContext (or you can add it later through sc.addPyFile).
对于使用 setuptools 的 Python 库,您可以运行 python setup.py bdist_egg
来构建一个 egg 发行版.
For Python libraries that use setuptools, you can run python setup.py bdist_egg
to build an egg distribution.
另一种选择是在集群范围内安装库,方法是在每台机器上使用 pip/easy_install 或通过集群范围的文件系统(如 NFS)共享 Python 安装.
Another option is to install the library cluster-wide, either by using pip/easy_install on each machine or by sharing a Python installation over a cluster-wide filesystem (like NFS).
这篇关于将 pyspark 中的 Python 模块传送到其他节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!