Kivy 的安装方式因操作系统而异,下面是在 Windows、Linux 和 macOS 上安装 Kivy 的基本步骤:
Windows:
1、安装 Python:在 Python 官网下载安装包并安装,注意选择正确的版本(32位或64位)。
2、安装 Kivy:打开命令提示符(cmd),输入以下命令:
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com kivy
3、安装依赖库:安装一些必要的依赖库,以避免出现运行时错误。
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com docutils pygments pypiwin32 kivy_deps.sdl2==0.2.0 kivy_deps.glew==0.2.0
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com kivy_deps.gstreamer==0.2.0
4. 安装 kivy 官方示例:
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com kivy_examples
Linux(Ubuntu):
1、安装 Python:在终端中输入以下命令:
sudo apt-get install python3
2、安装 Kivy:在终端中输入以下命令:
sudo apt-get install python3-kivy
3、安装依赖库:安装一些必要的依赖库,以避免出现运行时错误。
sudo apt-get install -y \
python3-setuptools \
build-essential \
python3-dev \
python3-pygame \
libsdl2-dev \
libsdl2-image-dev \
libsdl2-mixer-dev \
libsdl2-ttf-dev \
libportmidi-dev \
libswscale-dev \
libavformat-dev \
libavcodec-dev \
zlib1g-dev
macOS:
1、安装 Homebrew:在终端中输入以下命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2、安装 Python:在终端中输入以下命令:
brew install python
3、安装 Kivy:在终端中输入以下命令:
pip3 install kivy
4、安装依赖库:安装一些必要的依赖库,以避免出现运行时错误。
brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
安装完成后,可以通过在终端或命令提示符中输入 python 命令进入 Python 解释器,并尝试导入 Kivy 模块,以检查 Kivy 是否已成功安装。