anaconda 安装 chatterbot:问题集中营

你在这里

anaconda 安装 chatterbot:问题集中营

一、运行conda install chatterbot或pip install chatterbot
命令如下: pip install chatterbot
报错:
ERROR: Could not find a version that satisfies the requirement chatterbot (from versions: none)
ERROR: No matching distribution found for chatterbot
后指定清华源运行则可安装:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple chatterbot
二、运行chatterbot
在ipython中运行
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot("myBot")
报错:
AttributeError: module 'time' has no attribute 'clock'
这是因为清华源的chatterbot版本太老,只能运行在python3.5以下的版本,因此弃用之。
三、Python 3.8 安装chatterbot 1.1.0a7

直接寻找适用于python 3.8的版本,目前位于https://github.com/gunthercox/ChatterBot

未来可能还要更新,因此将该版本转移至百度云盘,以便未来使用:

链接:https://pan.baidu.com/s/1qCGL77TsZQyczHzUG1XSpA 
提取码:1234

然后解压下载下来的包ChatterBot-master.zip,并在win10命令行中运行

pip install D:\doc\aliyun\doc\stock\iwencai\ChatterBot-master chatterbot
报错:
Collecting sqlalchemy<1.4,>=1.3
  Using cached SQLAlchemy-1.3.24-cp38-cp38-win_amd64.whl (1.2 MB)
Requirement already satisfied: pytz in c:\users\zhu\anaconda3\lib\site-packages (from ChatterBot==1.1.0a7) (2021.3)
ERROR: Package 'chatterbot' requires a different Python: 3.8.12 not in '<=3.8,>=3.4'
于是直接从清华源站https://pypi.tuna.tsinghua.edu.cn/simple/sqlalchemy/下载:SQLAlchemy-1.3.24-cp38-cp38-win_amd64.whl,然后将它拷贝到C:\Users\zhu\anaconda3\pkgs目录下,运行以下命令:
 
cd C:\Users\zhu\anaconda3\pkgs
pip install --user  SQLAlchemy-1.3.24-cp38-cp38-win_amd64.whl
运行后报以下问题:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
chatterbot 1.0.4 requires sqlalchemy<1.3,>=1.2, but you have sqlalchemy 1.3.24 which is incompatible.
Successfully installed SQLAlchemy-1.3.24
这是说 SQLAlchemy-1.3.24与当前系统中已经安装了的来去清华源的chatterbot1.0.4不兼容,因为本来就要安装 ChatterBot 1.1.0a7,所以忽略报错。
接下来再次运行本地下载的chatterbot 1.1.0a7的安装程序:
cd D:\doc\aliyun\doc\stock\iwencai\ChatterBot-master
D:
python setup.py install
pip install D:\doc\aliyun\doc\stock\iwencai\ChatterBot-master chatterbot
*
这次,不再报错,直接运行完整个安装程序:
Successfully built ChatterBot
Installing collected packages: ChatterBot
  Attempting uninstall: ChatterBot
    Found existing installation: ChatterBot 1.1.0a7
    Uninstalling ChatterBot-1.1.0a7:
      Successfully uninstalled ChatterBot-1.1.0a7
Successfully installed ChatterBot-1.1.0a7
四、nlpk下载初始化失败
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer

chatbot = ChatBot("myBot")
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."
])
response = chatbot.get_response('I would like to book a flight.')
print(response)
报错:
Traceback (most recent call last):
File "C:\Users\zhu\AppData\Local\Temp/ipykernel_16764/914666704.py", line 1, in <module>
    chatbot = ChatBot("myBot")
File "C:\Users\zhu\anaconda3\lib\site-packages\chatterbot\chatterbot.py", line 28, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\zhu\anaconda3\lib\site-packages\chatterbot\utils.py", line 33, in initialize_class
    return Class(*args, **kwargs)
File "C:\Users\zhu\anaconda3\lib\site-packages\chatterbot\storage\sql_storage.py", line 20, in __init__
    super().__init__(**kwargs)
File "C:\Users\zhu\anaconda3\lib\site-packages\chatterbot\storage\storage_adapter.py", line 23, in __init__
    'tagger_language', languages.ENG
File "C:\Users\zhu\anaconda3\lib\site-packages\chatterbot\tagging.py", line 26, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
  File "C:\Users\zhu\anaconda3\lib\site-packages\spacy\__init__.py", line 52, in load
    name, vocab=vocab, disable=disable, exclude=exclude, config=config
File "C:\Users\zhu\anaconda3\lib\site-packages\spacy\util.py", line 355, in load_model
    raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name]))  # type: ignore[index]
OSError: [E941] Can't find model 'en'. It looks like you're trying to load a model from a shortcut, which is obsolete as of spaCy v3.0. To load the model, use its full name instead:
nlp = spacy.load("en_core_web_sm")
For more details on the available models, see the models directory: https://spacy.io/models. If you want to create a blank model, use spacy.blank: nlp = spacy.blank("en")
 

运行ChatBot("myBot")时,遇到OSError: [E050] Can‘t find model ‘en‘. It doesn‘t seem to be a shortcut link。

这是因为自然语言学习包NLP安装的spacy包需要调用一个英语模块,但是系统中没有找到缘故。此时在anaconda包目录(C:\Users\zhu\anaconda3\Lib\site-packages\)下查找一下,看看有没有en开头的包,例如en_core_web_sm,或en_core_web_md,如果没有则需要安装相关的包:

pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.1/en_core_web_sm-2.3.1.tar.gz
安装完毕后,en_core_web_sm文件夹会出现在C:\Users\zhu\anaconda3\Lib\site-packages\目录中。但是此时运行上述代码依然会报一样的错误。还是没有找到en包,此时可以在命令python命令行中测试一下
import spacy
nlp = spacy.load('en_core_web_sm')
如果能成功运行,则需要最后一步:为en_core_web_sm模块创建spacy的用户快捷模式,以管理员身份在命令行中运行:
python -m spacy link en_core_web_sm en
PS:上述指令将会在spacy/data目录下创建模型的快捷方式。第一个参数是模型名词(模型已经通过pip安装),或模型存放目录。第二个参数是你想使用的内部名词。设置--force标记将会强制覆盖已存在的连接。
 
此后,再次运行代码就不会报错了。
下面是示例:
from chatterbot import ChatBot  
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot("myBot")
trainer = ChatterBotCorpusTrainer(chatbot)
lineCounter = 1  
# 开始对话  
while True:  
    print(chatbot.get_response(input("(" + str(lineCounter) + ") user:")))  
    lineCounter += 1
    
运行到trainer = ChatterBotCorpusTrainer(chatbot)时输出为:
trainer.train("chatterbot.corpus.chinese")
Training ai.yml: [####################] 100%
Training botprofile.yml: [####################] 100%
Training conversations.yml: [####################] 100%
Training emotion.yml: [####################] 100%
Training food.yml: [####################] 100%
Training gossip.yml: [####################] 100%
Training greetings.yml: [####################] 100%
Training history.yml: [####################] 100%
Training humor.yml: [####################] 100%
Training literature.yml: [####################] 100%
Training money.yml: [####################] 100%
Training movies.yml: [####################] 100%
Training politics.yml: [####################] 100%
Training psychology.yml: [####################] 100%
Training science.yml: [####################] 100%
Training sports.yml: [####################] 100%
Training trivia.yml: [####################] 100%

最终运行结果如下图:

 
著作权归作者所有。商业转载请联系本站作者获得授权,非商业转载请注明出处 ZZKOOK

您可能感兴趣的文章

登录以发表评论

评论

这么多的好内容,先收下了?!!

 
156
图灵的头像

真是个难懂的系统

 
154
未遂平生的头像

谢谢分享!!!

 
156
山野客的头像

不错不错,赞一个!

 
146
sweeter的头像

给你发一张好人卡

 
155
陈欢的头像