使用pip安装Kivy时出错,求问题原因及解决办法
Hey there, let's work through your Kivy installation issues using the error logs you shared. Here are the key problems and step-by-step fixes:
Key Issues Identified
- Missing
wheelpackage: This caused the Cython build to fail witherror: invalid command 'bdist_wheel' - Network timeout: Your connection to PyPI timed out while fetching dependencies like Cython
- Missing
pkg-configtool: Windows doesn't include this by default, but Kivy needs it to resolve system dependencies - Cython version misalignment: Kivy requires a specific range of Cython versions that wasn't properly installed due to the above issues
Step-by-Step Fixes
1. Install/Upgrade Core Packaging Tools
First, ensure all essential packaging tools are up to date (even if you tried this before, a fresh run ensures no residual issues):
python -m pip install --upgrade pip setuptools wheel
2. Manually Install the Required Cython Version
Kivy specifies a strict Cython version range. Install it directly to avoid build conflicts:
python -m pip install "cython>=0.24,<=0.29.10,!=0.27,!=0.27.2"
3. Set Up pkg-config for Windows
Windows doesn't ship with pkg-config, which Kivy uses to locate system libraries like SDL and GStreamer:
- Download the GTK+ Runtime Environment Installer (it includes
pkg-config) matching your system architecture (32/64-bit) - After installation, find the
binfolder in the installation directory (e.g.,C:\Program Files\GTK3-Runtime Win64\bin) - Add this folder path to your System Environment Variables > PATH
- Restart your command prompt, then verify it works by running:
pkg-config --version
4. Install Kivy with a Stable Mirror and Extended Timeout
Use a reliable PyPI mirror to avoid network timeouts, and extend the timeout limit to prevent interruptions:
python -m pip install kivy --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple
Alternative: Use Precompiled Kivy Wheels
If compiling from source still fails, you can use pre-built Kivy wheel files (no compilation needed). Download the wheel file matching your Python version and Windows architecture, then install it with:
python -m pip install path/to/kivy-wheel-file.whl
内容的提问来源于stack exchange,提问作者12ksins

