28 Aug 2020

Chatterbot-Installation unter Gentoo Linux

Unter Gentoo ist die Installation des Chatterbots ein wenig diffiziler. Das liegt am –user Zwang von pip. Man kriegst aber trotzdem hin. Ein Installationsprotokoll.


Als Test-Program für die Installation wird charlie.py verwendet. Die Dokumentation ist hier zu finden: https://chatterbot.readthedocs.io/en/stable/examples.html#simple-example


Test-Programm charlie.py

#!/usr/bin/python3.6
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer

# Create a new chat bot named Charlie
chatbot = ChatBot('Charlie')

trainer = ListTrainer(chatbot)

trainer.train([
    "Hi, can I help you?",
    "Sure, I'd like to book a flight to Iceland.",
    "Your flight has been booked."
])

# Get a response to the input text 'I would like to book a flight.'
response = chatbot.get_response('I would like to book a flight.')

print(response)

Chatterbot installation

chrissie@fehmarn ~ $ python --version
Python 3.6.11

chrissie@fehmarn ~ $ pip install --user chatterbot
Collecting chatterbot
  Downloading ChatterBot-1.0.8-py2.py3-none-any.whl (63 kB)
     |################################| 63 kB 149 kB/s
Collecting mathparse<0.2,>=0.1
  Downloading mathparse-0.1.2-py3-none-any.whl (7.2 kB)
Collecting python-dateutil<2.9,>=2.8
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
     |################################| 227 kB 1.8 MB/s
Collecting sqlalchemy<1.4,>=1.3
  Downloading SQLAlchemy-1.3.19-cp36-cp36m-manylinux2010_x86_64.whl (1.3 MB)
     |################################| 1.3 MB 1.6 MB/s
Requirement already satisfied: pytz in /usr/lib64/python3.6/site-packages (from chatterbot) (2020.1)
Requirement already satisfied: six>=1.5 in /usr/lib64/python3.6/site-packages (from python-dateutil<2.9,>=2.8->chatterbot) (1.15.0)
Installing collected packages: mathparse, python-dateutil, sqlalchemy, chatterbot
Successfully installed chatterbot-1.0.8 mathparse-0.1.2 python-dateutil-2.8.1 sqlalchemy-1.3.19


Erster Test:

chrissie@fehmarn ~ $ ./charlie.py

ModuleNotFoundError: No module named 'spacy'

Es muss also spacy installiert werden

chrissie@fehmarn ~ $ pip install --user spacy
Collecting spacy
[...]


Zweiter Test:

chrissie@fehmarn ~ $ ./charlie.py

Traceback (most recent call last):
  File "./charlie.py", line 7, in <module>
    chatbot = ChatBot('Charlie')
  File "/home/chrissie/.local/lib64/python3.6/site-packages/chatterbot/chatterbot.py", line 28, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "/home/chrissie/.local/lib64/python3.6/site-packages/chatterbot/utils.py", line 33, in initialize_class
    return Class(*args, **kwargs)
  File "/home/chrissie/.local/lib64/python3.6/site-packages/chatterbot/storage/sql_storage.py", line 20, in __init__
    super().__init__(**kwargs)
  File "/home/chrissie/.local/lib64/python3.6/site-packages/chatterbot/storage/storage_adapter.py", line 21, in __init__
    'tagger_language', languages.ENG
  File "/home/chrissie/.local/lib64/python3.6/site-packages/chatterbot/tagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
  File "/home/chrissie/.local/lib64/python3.6/site-packages/spacy/__init__.py", line 30, in load
    return util.load_model(name, **overrides)
  File "/home/chrissie/.local/lib64/python3.6/site-packages/spacy/util.py", line 170, in load_model
    return load_model_from_package(name, **overrides)
  File "/home/chrissie/.local/lib64/python3.6/site-packages/spacy/util.py", line 190, in load_model_from_package
    cls = importlib.import_module(name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'en'

Installation des Spicy-Modules en

Hier fehlt nicht das Python-Modul en, sondern das Spicy-Modul en. Wegen der Gentoo-Beschränkungen kann es nicht mit python -m spacy download en installiert werden. Der Vorgang muss manuell durchgeführt werden, und auch ein Symlink mit en muss angelegt werden. Für andere Sprachen ist es obligatorisch, dass das richtige Modul gewählt werden muss.

chrissie@fehmarn ~ $ wget https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz

chrissie@fehmarn ~ $  pip install --user en_core_web_sm-2.3.1.tar.gz
Processing ./en_core_web_sm-2.3.1.tar.gz

cd /home/chrissie/.local/lib64/python3.6/site-packages/
ln -s en_core_web_sm en


Dritter Test

chrissie@fehmarn ~ $ ./charlie.py 
List Trainer: [####################] 100%
Your flight has been booked

Cheers!