Rasa 官网提供了多种安装方式:Local Mode、Quick-Installation、Helm Chart Installation 以及 Docker Compose Installation。这里我们选择 Local Mode 安装方式,在 Python 虚拟环境中进行 Rasa 的安装,可以做到与系统环境的隔离,保证其他环境不会收到影响。

1. Local Mode

Rasa X 是依赖于 Rasa,所以首先需要安装 Rasa,且 Rasa 使用的是 Sanic,它对 Python 版本也有一定要求,只能是 3.6 ~ 3.8,这里推荐使用使用 Python 3.8 版本。

实际安装下来,Rasa 基本功能的使用几乎没有问题,但是如果你想体验 Rasa X 的话,且使用的是 WSL2 Linux(实际 Linux 物理机测试下来并没有这些问题),那么运行后肯能会出现以下问题:

  • ImportError: cannot import name 'RowProxy' from 'sqlalchemy.engine' :这个是 SQLAlchemy 版本问题,安装 SQLAlchemy 的 1.3.24 即可。
  • RuntimeError: Event loop is closed:触发这种错误的因素有很多,比如 WSL2 中 Namesver 与 IP 不一致,所使用 aiohttp 版本不兼容,兼容的版本为 3.6.3。
  • asyncio.exceptions.TimeoutError:这是由于 Sanic 版本的问题,建议安装 20.6.3 版本
  • /usr/bin/xdg-open: 851: /usr/bin/xdg-open: firefox: not found
  • socket.gaierror: Name or service not known:这个一般由于 DNS 设置的问题,在 /etc/resolv.conf 中添加以下内容,同时在 /etc/hosts 中添加 0.0.0.0 irasax.com,且需要重启服务器。
  • Cannot connect to host stuff:5005 ssl:default [Name or service not known]:在 /etc/hosts 添加 127.0.0.1 stuff
    1. nameserver 8.8.8.8
    2. nameserver 8.8.4.4

为了尝试出一个比较稳定的版本,我做了以下多个环境的尝试。值得注意的是,Rasa 的版本均为 2.8.12,以下打钩的方案为成功测试且无 BUG 的。

  • 第一种 Rasa X:0.42.2
  • [ ] 第二种 Rasa X 版本为 0.41.2,但是 asyncio.exceptions.TimeoutError 报错始终无法解决。

    1. pip install --extra-index-url https://pypi.rasa.com/simple \
    2. --use-deprecated=legacy-resolver \
    3. rasa==2.8.12 rasa-x==0.41.2 sanic==20.6.3 kafka-python==1.4.7 \
    4. questionary==1.5.2 ujson==1.35 attrs==19.3 requests==2.25.1 idna==2.10 \
    5. sqlalchemy==1.3.24 aiohttp==3.6.3 pyjwt==2.0.0 chardet==3.0.4 uvloop==0.14.0 \
    6. gast==0.4.0 six==1.15.0 typing-extensions==3.7.4.3 decorator==4.4.2
  • [x] 第三种 Rasa X:0.40.1

    1. pip install --extra-index-url https://pypi.rasa.com/simple \
    2. --use-deprecated=legacy-resolver \
    3. rasa==2.8.12 rasa-x==0.40.1 sanic==20.6.3 kafka-python==1.4.7 \
    4. questionary==1.5.2 ujson==1.35 attrs==19.3 requests==2.25.1 idna==2.10 \
    5. sqlalchemy==1.3.24 aiohttp==3.6.3 pyjwt==2.0.0 chardet==3.0.4 uvloop==0.14.0 \
    6. gast==0.4.0 six==1.15.0 typing-extensions==3.7.4.3 decorator==4.4.2
  • [x] 第四种 Rasa X:0.39.3

    1. pip install --extra-index-url https://pypi.rasa.com/simple \
    2. --use-deprecated=legacy-resolver \
    3. rasa==2.8.12 rasa-x==0.39.3 sanic==20.6.3 kafka-python==1.4.7 \
    4. questionary==1.5.2 ujson==1.35 attrs==19.3 requests==2.25.1 idna==2.10 \
    5. sqlalchemy==1.3.24 aiohttp==3.6.3 pyjwt==2.0.0 chardet==3.0.4 uvloop==0.14.0 \
    6. gast==0.4.0 six==1.15.0 typing-extensions==3.7.4.3 decorator==4.4.2

⭐ 这里需要注意的时,rasarasa-x 一定要添加版本号,以及 --use-deprecated=legacy-resolver ,不然 pip 会所有历史版本,耗时非常长,必要库的版本号也一起标出来了,请一起安装。

除此之外,还有一个问题的目前未找到解决方案,报错信息如下,在 WIN11 上 WSL2 上启动时间非常长(通常需要 30 分钟),但是在 WIN10 上 WSL2 并不会出现这个问题:

  1. 2021-11-18 08:51:37 DEBUG urllib3.connectionpool - https://api.segment.io:443 "POST /v1/track HTTP/1.1" 200 21
  2. 2021-11-18 08:51:37 DEBUG rasa.core.agent - Requesting model from server http://localhost:5002/api/projects/default/models/tags/production...
  3. 2021-11-18 08:51:37 DEBUG rasa.core.agent - Tried to fetch model from server, but couldn't reach server. We'll retry later... Error: Cannot connect to host localhost:5002 ssl:default [Connection refused].
  4. 2021-11-18 08:51:37 DEBUG rasa.core.agent - No new model found at URL http://localhost:5002/api/projects/default/models/tags/production

1.1 Rasa3.1+Rasa-SDK3.1+RasaX1.1

  1. ERROR: pip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.
  2. tensorflow 2.8.0 requires numpy>=1.20, but you'll have numpy 1.19.5 which is incompatible.
  3. rasa 3.1.0 requires sanic-cors<3.0.0,>=2.0.0, but you'll have sanic-cors 1.0.0 which is incompatible.
  4. rasa 3.1.0 requires tensorflow<2.8.0,>=2.7.0, but you'll have tensorflow 2.8.0 which is incompatible.
  5. rasa-x 1.1.0 requires sanic-cors<3.0.0,>=2.0.0, but you'll have sanic-cors 1.0.0 which is incompatible.
  6. rasa-sdk 3.1.1 requires Sanic-Cors<3.0.0,>=2.0.0, but you'll have sanic-cors 1.0.0 which is incompatible.
  7. sanic-plugin-toolkit 1.2.1 requires sanic<21.12.0,>=21.3.1, but you'll have sanic 21.12.1 which is incompatible.
  1. $ brew install libxml2 libxmlsec1 pkg-config libxml2-dev libxmlsec1-dev libxmlsec1-openssl
  2. $ conda install lxml==4.6.5
  3. $ conda install -c conda-forge xmlsec==1.3.12
  4. $ pip install psycopg2_binary==2.9.3 tensorflow==2.7.1
  5. $ pip install -i https://pypi.org/simple/ grpcio==1.46.1 botocore==1.27.11
  6. $ pip install --extra-index-url https://pypi.rasa.com/simple --use-deprecated=legacy-resolver \
  7. rasa==3.1.0 rasa-sdk==3.1.1 rasa-x==1.1.1 sanic==21.12.1 multidict==5.2.0 \
  8. tensorflow==2.7.1 tensorflow-text==2.7.3 Sanic-Cors==2.0.0 sanic-jwt==1.7.0 pyjwt==2.1.0 \
  9. attrs==19.3.0 networkx==2.5.1 questionary==1.5.2 ujson==1.35 sanic-plugin-toolkit==1.2.0

参考文档:

3. Helm Chart Installation

4. Docker Compose Installation