简体   繁体   中英

AWS Lambda -- Unable to import srsly.ujson.ujson for SpaCy

I am trying to add SpaCy as a dependency to my Python Lambda. I am doing this by installing SpaCy as a standalone dependency inside a directory named dependencies using pip3 install spacy --no-deps -t . This is because I can't load the entire Spacy dependency inside the \\tmp directory of my Lambda.

I am able to successfully upload the folder to s3 and download it during the Lambda invocation. When I try to import spacy , I get this error: [ERROR] Runtime.ImportModuleError: Unable to import module : No module named 'srsly.ujson.ujson' .

I manually installed srsly inside dependencies\\ and I have all the files that are listed as per this link . This was referenced by this link . One of the responses says, "it seems like Python can't load it, because it's not compiled?". How would I compile a dependency which has a .c file in it?

One other question which I found on SO is this question , but I have already manually installed srsly . How to I import the module? Thanks.


I manually check in my code for the presence of ujson before importing spacy like this:

if os.path.exists('/tmp/dependencies/srsly/ujson/ujson.c'):
    print('ujson exists')

and the print statement gets printed.

嗯,这有点奇怪,但我对这个问题的解决方案是在 srsly 文件夹中创建一个额外的“ujson”文件夹,然后将所有 ujson 生成的代码移动到之前创建的文件夹“ujson”

对我来说,pip 卸载和安装 srsly 再次工作正常.. 有时它只是与您的 python 版本的兼容性问题,因此请确保存在正确的 python/srsly 版本

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM