Python 在AWS Lambda上使用Pyenchant,可以加载包,但不能加载提供程序字典,可以从EC2上的源代码编译并提取.so文件

Python 在AWS Lambda上使用Pyenchant,可以加载包,但不能加载提供程序字典,可以从EC2上的源代码编译并提取.so文件,python,aws-lambda,aspell,pyenchant,enchant,Python,Aws Lambda,Aspell,Pyenchant,Enchant,我试图在AWS上的Lambda函数中使用Python拼写检查库Pyenchant。Pyenchant是C libenchant库的包装器,而C libenchant库又依赖于Aspell等提供程序提供的单词词典 在Lambda上运行的python代码中,我能够成功导入enchant库,并在AWS linux EC2实例上编译了它和C库(libenchant.so),并将输出复制到Lambda部署包中 但是,pyenchant库在Lambda上运行时无法加载任何需要工作的单词词典。然后,我使用以下

我试图在AWS上的Lambda函数中使用Python拼写检查库Pyenchant。Pyenchant是C libenchant库的包装器,而C libenchant库又依赖于Aspell等提供程序提供的单词词典

在Lambda上运行的python代码中,我能够成功导入enchant库,并在AWS linux EC2实例上编译了它和C库(libenchant.so),并将输出复制到Lambda部署包中

但是,pyenchant库在Lambda上运行时无法加载任何需要工作的单词词典。然后,我使用以下方法在EC2实例上安装了Aspell:

yum install aspell-en enchant-aspell
然后,我将以下附加的.so文件复制到部署包的/lib文件夹中:

  • 利巴斯佩尔
  • 利班查特·阿斯佩尔·索
  • Libench_ispell.so
  • Libench_myspell.so
  • 李白
我很确定libenchant_aspell.so才是真正的字典,但它没有收录,我也不知道下一步该去哪里

下面是我的lambda_处理器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个小时的大部分时间试图弄明白如何让它工作。提前感谢你的帮助

好吧,对于遇到这个问题的任何其他人(可能没有人…),结果是不可能在Lambda上使用这个包。这与没有合适的基础结构来加载几个层次的共享对象资源有关。最后,我在EC2上使用了一个flask web服务器,它工作得很好。

结果是有一个人遇到了这个问题。。。因为这是我在研究这个问题时第一次偶然发现的地方,我希望一年半后会有一个解决方案。。。