我想在AWS上的Lambda函數中使用Python拼寫檢查庫Pyenchant。 Pyenchant是C libenchant庫的封裝,它依賴於Aspell等提供者的單詞詞典。在AWS Lambda上使用Pyenchant,可以加載包而不是提供者字典,已經從EC2上的源代碼編譯並提取.so文件
在我運行在Lambda上的Python代碼中,我能夠成功導入已編譯它的附魔庫和C庫(libenchant.so)到AWS Linux EC2實例並將輸出複製到我的Lambda部署包。
但是,pyenchant庫在Lambda上運行時無法加載任何需要工作的單詞詞典。
yum install aspell-en enchant-aspell
我再複製以下附加.so文件到我的部署包的/ lib文件夾:
- libaspell.so
- libenchant_aspell.so 我然後使用安裝在安博泰EC2實例
- libenchant_ispell.so
- libenchant_myspell.so
- libenchant.so
我敢肯定libenchant_aspell.so是實際的字典,但它沒有拿起它,我無法找出下一步去哪裏。
下面是我lambda_handler Python代碼:
from __future__ import print_function
import os
import sys
import re
import enchant
enchant.set_param("enchant.aspell.dictionary.path","/var/task/lib")
def lambda_handler(event, context):
print("# List available enchant dictionary languages")
print(enchant.list_languages())
b = enchant.Broker()
print("# List available enchant brokers")
print(b.describe())
d = enchant.Dict("en_GB")
# print(d.provider.name)
# print(d.provider.file)
return "Done"
這裏是從調用lambda函數的輸出:
START RequestId: 7539245b-d3d6-11e6-b7e6-edc1dc8cbdd4 Version: $LATEST
# List available enchant dictionary languages
[]
# List available enchant brokers
[]
Dictionary for language 'en_GB' could not be found: DictNotFoundError
Traceback (most recent call last):
File "/var/task/package_test.py", line 16, in lambda_handler
d = enchant.Dict("en_GB")
File "/var/task/enchant/__init__.py", line 558, in __init__
_EnchantObject.__init__(self)
File "/var/task/enchant/__init__.py", line 168, in __init__
self._init_this()
File "/var/task/enchant/__init__.py", line 565, in _init_this
this = self._broker._request_dict_data(self.tag)
File "/var/task/enchant/__init__.py", line 310, in _request_dict_data
self._raise_error(eStr % (tag,),DictNotFoundError)
File "/var/task/enchant/__init__.py", line 258, in _raise_error
raise eclass(default)
DictNotFoundError: Dictionary for language 'en_GB' could not be found
END RequestId: 7539245b-d3d6-11e6-b7e6-edc1dc8cbdd4
REPORT RequestId: 7539245b-d3d6-11e6-b7e6-edc1dc8cbdd4 Duration: 1.03 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 16 MB
正如你可以看到import enchant
工作正常,但無法找到任何的字典文件。
我真的被困在這,花了6個小時的最佳部分試圖找出如何得到這個工作。在此先感謝您的幫助。