Paths in AWS lambda with Python NLTK

后端 未结 3 641
时光说笑
时光说笑 2021-01-03 03:00

I\'m encountering problems with the NLTK package in AWS Lambda. However I believe the issue is related more to path configurations in Lambda being incorrect. NLTK is having

3条回答
  •  自闭症患者
    2021-01-03 03:28

    So I've found the answer to this question. After a couple of days messing around I've finally figured it out. The data.py file in the nltk folder needs to be modified as follows. Basically remove the /usr/... paths and add in the folder that Lambda executes from /var/task/ and ensure that your nltk_data folder is in the root of your execution zip.

    Not sure why, but using the inline nltk.data.path.append() method does not work with AWS Lambda and the data.py file needs to be modified directly.

    else:
        # Common locations on UNIX & OS X:
        path += [
            str('/var/task/nltk_data')
            #str('/usr/share/nltk_data'),
            #str('/usr/local/share/nltk_data'),
            #str('/usr/lib/nltk_data'),
            #str('/usr/local/lib/nltk_data')
        ]
    

提交回复
热议问题