Airtest 安装避坑指南
本文档记录了在 Python 3.13 环境下安装 Airtest 的成功经验和避坑指南,适用于遇到安装问题的用户参考。
环境信息
- 操作系统:Windows
- Python 版本:3.13(最新版本,可能与部分包存在兼容性问题)
- Airtest 版本:1.3.6
常见问题与解决方案
问题1:安装过程中缺少编译器
错误信息:
ERROR: Unknown compiler(s): [['icl'], ['cl'], ['cc'], ['gcc'], ['clang'], ['clang-cl'], ['pgcc']]
解决方案:使用预编译的 wheel 包,避免源码编译。
- 分享文件:Airtest-1.3.6.zip
- 链接:https://pan.xunlei.com/s/VOdWqEg9hk2B0K-H198sfGOnA1?pwd=y3ek#
复制这段内容后打开迅雷,查看更方便
问题2:meson-python 版本不匹配
错误信息:
ERROR: Could not find a version that satisfies the requirement meson-python<0.16.0,>=0.15.0
解决方案:安装预编译的 numpy wheel 包,或使用 --prefer-binary 参数。
问题3:numpy 版本兼容性问题
错误信息:
airtest 1.3.6 requires numpy<2.0, but you have numpy 2.3.4 which is incompatible.
解决方案:虽然有警告,但在大多数基本功能使用中可能不会有问题。如需完全兼容,可以降级 numpy 版本。
成功安装步骤
步骤1:升级 pip
首先确保 pip 是最新版本:
pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
步骤2:安装 numpy
使用国内镜像源安装预编译的 numpy:
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn --prefer-binary
步骤3:安装 Airtest(跳过依赖检查)
由于 Airtest 与最新版本的 numpy 存在版本限制,我们需要跳过依赖检查:
pip install airtest -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn --no-deps
步骤4:安装必要的依赖项
手动安装 Airtest 所需的依赖:
pip install six==1.16.0 mss==6.1.0 ffmpeg-python filelock opencv-contrib-python==4.6.0.66 pywinauto==0.6.3 tidevice -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
验证安装
创建一个简单的测试脚本验证 Airtest 是否正常工作:
# test_airtest.py
import airtest
print(f"Airtest版本: {airtest.__version__}")
print("Airtest导入成功!")
运行脚本:
python test_airtest.py
如果输出 Airtest 版本并显示导入成功,则安装成功。
避坑指南
-
避免直接从 ZIP 文件安装:虽然可以通过
pip install "路径/Airtest-1.3.6.zip"安装,但在高版本 Python 中可能会遇到更多依赖问题。 -
优先使用国内镜像源:使用清华大学、阿里云等国内镜像源可以显著提高下载速度并避免网络问题。
-
注意版本兼容性:
- Airtest 1.3.6 要求 numpy < 2.0
- 在 Python 3.13 环境中,许多包可能尚未完全兼容
-
使用 --prefer-binary 避免源码编译:这可以避免因缺少编译器导致的安装失败。
-
手动安装依赖:使用
--no-deps安装 Airtest 后,需要手动安装所有必要的依赖项。
高级选项:使用虚拟环境
为避免依赖冲突,推荐使用虚拟环境安装 Airtest:
# 创建虚拟环境
python -m venv airtest_env# 激活虚拟环境
airtest_env\Scripts\activate# 然后在虚拟环境中按照上述步骤安装 Airtest
故障排除
如果在使用过程中遇到 numpy 相关的错误,可以尝试降级 numpy 版本:
pip install numpy==1.26.4 -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn --prefer-binary
如果问题仍然存在,可能需要考虑使用较低版本的 Python(如 Python 3.8-3.10),这些版本与 Airtest 的兼容性更好。
总结
在高版本 Python(如 3.13)中安装 Airtest 需要注意依赖兼容性问题。通过使用国内镜像源、预编译 wheel 包和手动管理依赖,可以成功安装并使用 Airtest 的基本功能。对于复杂项目,建议使用较低版本的 Python 以获得更好的兼容性。