2021-12-27 22:08:59 +08:00
|
|
|
|
---
|
|
|
|
|
sidebar_position: 0
|
2022-02-05 19:46:33 +08:00
|
|
|
|
description: 通过脚手架、PyPI 或 GitHub 安装 NoneBot2
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
options:
|
|
|
|
|
menu:
|
|
|
|
|
weight: 10
|
|
|
|
|
category: guide
|
|
|
|
|
---
|
|
|
|
|
|
2022-01-27 21:24:56 +08:00
|
|
|
|
import Asciinema from "@site/src/components/Asciinema";
|
|
|
|
|
|
2022-02-05 19:46:33 +08:00
|
|
|
|
# 安装 NoneBot2
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
:::warning 注意
|
2022-08-14 19:41:00 +08:00
|
|
|
|
请确保你的 Python 版本 >= 3.8。
|
2021-12-27 22:08:59 +08:00
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
:::warning 注意
|
|
|
|
|
请在安装 NoneBot v2 之前卸载 NoneBot v1
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pip uninstall nonebot
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
:::
|
|
|
|
|
|
2022-02-05 19:46:33 +08:00
|
|
|
|
## 通过脚手架安装(推荐)
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
2023-01-22 15:18:26 +08:00
|
|
|
|
1. 安装 [pipx](https://pypa.github.io/pipx/)
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
2023-01-22 15:18:26 +08:00
|
|
|
|
python -m pip install --user pipx
|
|
|
|
|
python -m pipx ensurepath
|
2021-12-27 22:08:59 +08:00
|
|
|
|
```
|
|
|
|
|
|
2023-01-22 15:18:26 +08:00
|
|
|
|
2. 安装脚手架
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pipx install nb-cli
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
安装完成后,你可以在命令行使用 `nb` 命令来使用脚手架。如果出现无法找到命令的情况(例如:`Command not found`),请参考 [pipx 文档](https://pypa.github.io/pipx/) 检查你的环境变量。
|
|
|
|
|
|
2022-01-27 21:24:56 +08:00
|
|
|
|
<Asciinema
|
|
|
|
|
url="https://asciinema.org/a/464654.cast"
|
|
|
|
|
options={{ theme: "monokai", poster: "npt:2.8" }}
|
|
|
|
|
/>
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
:::important 提示
|
2022-02-05 19:46:33 +08:00
|
|
|
|
nb-cli 的使用方法详见[使用脚手架](./nb-cli.md)
|
2021-12-27 22:08:59 +08:00
|
|
|
|
:::
|
|
|
|
|
|
2022-02-05 19:46:33 +08:00
|
|
|
|
## 不使用脚手架(纯净安装)
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
2022-02-05 19:46:33 +08:00
|
|
|
|
如果你不想使用脚手架,可以直接安装 NoneBot2,并自行完成开发配置。
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
2023-01-06 20:07:28 +08:00
|
|
|
|
pip install nonebot2[fastapi]
|
2022-02-05 19:46:33 +08:00
|
|
|
|
# 也可以通过 Poetry 安装
|
2023-01-06 20:07:28 +08:00
|
|
|
|
poetry add nonebot2[fastapi]
|
2021-12-27 22:08:59 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 从 GitHub 安装
|
|
|
|
|
|
2022-01-27 21:24:56 +08:00
|
|
|
|
如果你需要使用最新的(可能**尚未发布**的)特性,可以直接从 GitHub 仓库安装:
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
:::warning 注意
|
2022-02-05 19:46:33 +08:00
|
|
|
|
直接从 GitHub 仓库中安装意味着你将使用最新提交的代码,它们并没有进行充分的稳定性测试
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
在任何情况下请不要将其应用于生产环境!
|
|
|
|
|
:::
|
|
|
|
|
|
2022-02-05 19:46:33 +08:00
|
|
|
|
```bash title="Install From GitHub"
|
2021-12-27 22:08:59 +08:00
|
|
|
|
# master分支
|
|
|
|
|
poetry add git+https://github.com/nonebot/nonebot2.git#master
|
|
|
|
|
# dev分支
|
|
|
|
|
poetry add git+https://github.com/nonebot/nonebot2.git#dev
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-27 21:24:56 +08:00
|
|
|
|
或者在克隆 Git 仓库后手动安装:
|
2021-12-27 22:08:59 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
git clone https://github.com/nonebot/nonebot2.git
|
|
|
|
|
cd nonebot2
|
|
|
|
|
poetry install --no-dev # 推荐
|
|
|
|
|
pip install . # 不推荐
|
|
|
|
|
```
|