设置虚拟 Python 工作区#

To create a Python virtual environment using venv, ensure that Python is installed on your system. You can download the installer from python.org. The AIM WebSocket API requires Python 3.8 or later.

  • 在 Windows 上,安装过程中请务必勾选“将 Python 3.x 添加到 PATH”选项。这可能需要管理员权限。

  • 在 macOS 和大多数 Linux 发行版上,Python 3 通常是预装的,但验证版本仍然是个好主意。

1.创建虚拟环境#

From within the root directory of the clone repository, run the following:

python -m venv venv

2.激活虚拟环境#

From within the root directory of the clone repository, run the appropriate command for your operating system:

视窗#

Powershell 或命令提示符:

venv\Scripts\activate

Git Bash (MINGW64) - 不推荐:

source venv/Scripts/activate

macOS、Linux 和 WSL#

source venv/bin/activate

Note: To ensure your virtual environment is activated automatically, you can add the activation command to your shell’s startup file (e.g., .bashrc, .zshrc).

验证 Shell 环境#

要验证您的 shell 环境是否使用了正确的虚拟环境,请通过输入 REPL 启动 Python 会话:

python

然后运行以下命令:

import sys
print(sys.prefix)

输出应与您的虚拟环境目录的路径相匹配。

3.安装所需的软件包#

From within the root directory of the clone repository, run:

pip install -r requirements.txt

On macOS, if you encounter an error while installing pyaudio, first install the portaudio library using Homebrew, then try again:

brew install portaudio
pip install -r requirements.txt

On Debian/Ubuntu: Install portaudio19-dev using apt, and then re-run pip install -r requirements.txt:

sudo apt install portaudio19-dev
pip install -r requirements.txt

您现在可以在连接的机器人上运行 Python 脚本