2017-01-23 2 views
0

내 app.zip 파일의 루트에 app.py 파일이 있습니다. Unable to import module 'app': No module named appPython : AWS Lambda의 모듈 앱을 가져올 수 없습니다.

내가 잘못

갔지 : 그리고 기능 핸들러는 그러나 핸들러 설정 : app.lambda_handler

에 따라, (lambda_handler)가 제대로 정의, 나는 오류는 무엇입니까?

내 스크립트

내가 잘못 않았다
from __future__ import print_function 

import json 
import urllib 
import boto3 
from collections import Counter 
from nltk.tokenize import sent_tokenize, word_tokenize 
from nltk.corpus import stopwords 
from nltk.tokenize import RegexpTokenizer 
from nltk.stem.porter import * 
from nltk.corpus import stopwords 
from nltk.tokenize import RegexpTokenizer 
tokenizer = RegexpTokenizer(r'\w+') 
stemmer=PorterStemmer() 
import sys 
reload(sys) 
sys.setdefaultencoding('utf8') 


print('Loading function') 

s3 = boto3.client('s3') 

number_of_sentences=0 
number_of_words=0 
word_list=[] 
stop_words=set(stopwords.words('english')) 
stop_word_list=[ v for v in stop_words] 
modal_verbs=['can', 'could', 'may', 'might', 'must', 'shall', 'should', 'will' ,'would','ought'] 
auxilary_verbs=['be','do','have'] 
stop_word_list=stop_word_list+modal_verbs+auxilary_verbs 
print("Starting Trigram generation") 
#Empty Trigram list 
tri_gram_list=[] 

def lambda_handler(event, context): 
    #print("Received event: " + json.dumps(event, indent=2)) 

    # Get the object from the event and show its content type 
    ''' 
    ''' 
    bucket = event['Records'][0]['s3']['bucket']['name'] 
    key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8')) 
    try: 
     response = s3.get_object(Bucket=bucket, Key=key) 
     print("CONTENT TYPE: " + response['ContentType']) 
     text = response['Body'].read() 
     print(type(text)) 
     for line in text.readlines(): 
      for line in open("input.txt","r").readlines(): 
       line=unicode(line, errors='ignore') 
       if len(line)>1: 
        sentences=sent_tokenize(line) 
        number_of_sentences+=len(sentences) 
        for sentence in sentences: 
         sentence=sentence.strip().lower() 
         #sentence = sentence.replace('+', ' ').replace('.', ' ').replace(',', ' ').replace(':', ' ').replace('(', ' ').replace(')', ' ').replace(''`'', ' ').strip().lower() 
         words_from_sentence=tokenizer.tokenize(line) 
         words = [word for word in words_from_sentence if word not in stop_word_list] 
         number_of_words+=len(words) 
         stemmed_words = [stemmer.stem(word) for word in words] 
         word_list.extend(stemmed_words) 
         #generate Trigrams 
         tri_gram_list_t= [ " ".join([words[index],words[index+1],words[index+2]]) for index,value in enumerate(words) if index<len(words)-2] 
         #print tri_gram_list 
         tri_gram_list.extend(tri_gram_list_t) 

     print number_of_words 
     print number_of_sentences 
     print("Conting frequency now...") 
     count=Counter() 
     for element in tri_gram_list: 
      #print element, type(tri_gram_list) 
      count[element]=count[element]+1 
     print count.most_common(25) 
     print "most common 25 words ARE:" 
     for element in word_list: 
      #print element, type(tri_gram_list) 
      count[element]=count[element]+1 
     print count.most_common(25) 




     # body = obj.get()['Body'].read() 

    except Exception as e: 
     print(e) 
     print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket)) 
     raise e 

?

+0

print(number_of_words)에 의해 \ _ \ _ 초기화 \ _ \ _ 평을 디렉토리에 :.

마지막으로, 같은 전화를 교체, 당신은 파이썬이 구문이 필요하다는 것을 기억 하는가? – denvaar

+0

어디에서 스크립트를 실행 했습니까? 가져 오려는 모듈은 시스템 경로 또는 현재 경로 아래에 있어야합니다. – Flickerlight

+0

@denvaar 번호 필요합니까? – Dawny33

답변

0

로그 출력을 확인하십시오. 위에 나온 오류보다 많은 정보를 제공합니다. 당신이이 있나요

print number_of_words

관련 문제