2

コマンドを使用してpyahocorasickライブラリを構築python setup.py bdist_eggし、PySpark ジョブ用に Spark にアップロードしました。

pkg_resources.resource_filename()ただし、pyahocorasick 内の .so ファイルは、セキュリティ上の理由から、Spark クラスターのメソッドを介してインポートすることはできません。

Traceback (most recent call last):
  File "spark_datawash.py", line 251, in <module>
    import ahocorasick
  File "build/bdist.linux-x86_64/egg/ahocorasick.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/ahocorasick.py", line 4, in __bootstrap__
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1152, in resource_filename
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1696, in get_resource_filename
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1726, in _extract_resource
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1219, in get_cache_path
  File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1199, in extraction_error
pkg_resources.ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/home/.python-eggs'

The Python egg cache directory is currently set to:

  /home/.python-eggs

Perhaps your account does not have write access to this directory?  You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

これは、pyahocorasick が .so をインポートする方法です。

def __bootstrap__():
    global __bootstrap__, __loader__, __file__
    import sys, pkg_resources, imp 
    __file__ = pkg_resources.resource_filename(__name__, 'ahocorasick.so')
    __loader__ = None; del __bootstrap__, __loader__
    imp.load_dynamic(__name__,__file__)
__bootstrap__()

絶対ファイルパスから読み取る必要なしに、または他の方法resource_stream()で.so をインポートできますか? resource_filename()皆さんありがとう。

ところで、他の理由で、Spark クラスターのすべてのノードに pyahocorasick をインストールすることはできません。そのため、後で使用するために卵を圧縮したディストリビューションをアップロードする必要があります。

4

0 に答える 0