I built the pyahocorasick library with python setup.py bdist_egg
command and uploaded it onto Spark for my PySpark job.
However, the .so file inside pyahocorasick can't be imported through pkg_resources.resource_filename()
method on Spark cluster for security reasons.
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.
This is how pyahocorasick import the .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__()
Can I import the .so by resource_stream()
instead of resource_filename()
or some other way without the need to read from an absolute file path?
Thanks all.
BTW, I can't install pyahocorasick on every node on Spark cluster for other reasons. So I have to upload an egg-zipped distribution for later use.