Как запустить python скрипт с внешними пакетами, такими как textblob с oop streaming - PullRequest
0 голосов
/ 18 марта 2020

Я пытаюсь запустить код mapreduce в python с потоковой передачей oop. Я должен импортировать пакеты nltk и textblob как часть моего кода редуктора. Скрипты мапперов и редукторов прекрасно работают в моей локальной системе (windows), но когда я пытаюсь отправить их в систему hdfs с использованием потока oop, я сталкиваюсь с другими проблемами.

  1. В нем говорится, что пакеты nltk и textblob не найдены в системе hdfs. Используя эту ссылку, я следовал точно таким же шагам, но она дает мне ниже упомянутую ошибку

    Traceback (последний вызов был последним): файл "", строка 75, в init файл "", строка 87, в _path_stat FileNotFoundError: [WinError 3] Система не может найти путь указано: ''

    Во время обработки вышеупомянутого исключения произошло другое исключение:

    Traceback (последний вызов был последним): файл "C: \ had oop -3.2.0 \ temp \ reducer_movies.py ", строка 3, в файле import = zipimportx.zipimporter ('nltk.mod')" C: \ Python38-32 \ lib \ site-packages \ zipimportx__init __. py ", строка 190, в init zipimport.zipimporter. init (self, archivepath) Файл "", строка 81, в init zipimport.ZipImportError: не файл Zip

  2. Я попытался изменить .mod с помощью .zip, и я сталкиваюсь с этой ошибкой:

Traceback (последний вызов был последним): Файл "C: \ had oop -3.2.0 \ temp \ reducer_movies.py ", строка 3, в файле importer = zipimportx.zipimporter ('nltk.zip')" C: \ Python38-32 \ lib \ site-packages \ zipimportx__init __. py ", строка 190, в init zipimport.zipimporter. init (self, archivepath) Файл "", строка 96, в init AttributeError: невозможно установить атрибут

Я застрял в дальнейших действиях. Пожалуйста, смотрите мой код ниже:

#!/usr/bin/env python
import sys
from operator import itemgetter
import zipimportx
importer = zipimportx.zipimporter('C:\hadoop-3.2.0\temp\nltk.zip')
nltk = importer.load_module('nltk')

from nltk.tokenize import word_tokenize
nltk.data.path += ["."]

importer = zipimportx.zipimporter('C:\hadoop-3.2.0\temp\textblob.zip')
textblob = importer.load_module('textblob')

from textblob import classifiers
from textblob import TextBlob
textblob.data.path += ["."]

current_word = None
current_count = 0
word = None

training = [
        ('The lion king is an animation movie which is the story of a cub and his wicked uncle','Animation'),
        ('Shlykov, a hard-working taxi driver and Lyosha, a saxophonist, develop a bizarre love-hate relationship, and despite their prejudices, realize they aren''t so different after all','Drama'),
        ('The nation of Panem consists of a wealthy Capitol and twelve poorer districts. As punishment for a past rebellion, each district must provide a boy and girl between the ages of 12 and 18 selected by lottery for the annual Hunger Games. The tributes must fight to the death in an arena;','Adventure'),
        ('Poovalli Induchoodan is sentenced for six years prison life for murdering his classmate. Induchoodan, the only son of Justice Maranchery Karunakara Menon was framed in the case by Manapally Madhavan Nambiar and his crony DYSP Sankaranarayanan to take revenge on idealist judge Menon who had','Action'),
        ('The Lemon Drop Kid , a New York City swindler, is illegally touting horses at a Florida racetrack. After several successful hustles, the Kid comes across a beautiful, but gullible, woman intending to bet a lot of money. The Kid convinces her to switch her bet, employing a prefabricated con.','Comedy'),
        ('Seventh-day Adventist Church pastor Michael Chamberlain, his wife Lindy, their two sons, and their nine-week-old daughter Azaria are on a camping holiday in the Outback. With the baby sleeping in their tent, the family is enjoying a barbecue with their fellow campers when a cry is heard.','Crime Fiction'),
        ('Why was Elsa born with magical powers? The answer is calling her and threatening her kingdom. Together with Anna, Kristoff, Olaf and Sven, she''ll set out on a dangerous but remarkable journey. In Frozen, Elsa feared her powers were too much for the world. In Frozen 2, she must hope they are enough.','Animation'),
        ('this movie is about the drama of panipat','Drama')
        ]
#print(training)
classifier = classifiers.NaiveBayesClassifier(training)
def process_text(text):
    blob = TextBlob(text,classifier=classifier)
    return blob.classify()

# input comes from STDIN
for line in sys.stdin:   
    line = line.strip()
    lines = line.split('--')
    #print (lines)
    for x in lines:
        genre = process_text(x)
        #print(genre)
        print(x, genre) # This is for Python 3
...