You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions windows-latest环境下Kivy安装失败求助

Kivy在GitHub Actions Windows环境安装失败的解决方案

问题描述

尝试通过GitHub Actions自动化构建依赖Kivy的Python程序Windows二进制包,Linux和Windows手动构建版本可正常使用,但runs-on: windows-latest的工作流中Kivy安装失败,相同逻辑在ubuntu-latest环境运行正常。

GitHub Actions工作流

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: compile-source-windows

on:
  push:
    branches: [main, master]
    paths:
      - "**/src/*.py"
      - "**/src/*.bat"
      - "**/src/*.sh"
      - "**/compile-source-windows.yml"
  workflow_dispatch:

# on: workflow_dispatch
defaults:
  run:
    working-directory: "./source/01FormHelper/src/"

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: update pip and install python modules in pipenv
        run: |
          python -V
          pip install -U pip
          pip install pipenv
          pip install Kivy
          pip install kivy pyinstaller beautifulsoup4 setuptools cython 
          pipenv install cython 
          pipenv install kivy 
          pipenv install Kivy

错误日志

Installing kivy...
Error:  An error occurred while installing kivy!
Error text: Collecting kivy
  Downloading Kivy-2.1.0.tar.gz (23.8 MB)
     --------------------------------------- 23.8/23.8 MB 28.4 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'error'

  error: subprocess-exited-with-error
  
  � pip subprocess to install build dependencies did not run successfully.
  \u2502 exit code: 1
  \u2570\u2500> [13 lines of output]
      Collecting setuptools
        Downloading setuptools-66.1.1-py3-none-any.whl (1.3 MB)
           ---------------------------------------- 1.3/1.3 MB 26.6 MB/s eta 
0:00:00
      Collecting wheel
        Downloading wheel-0.38.4-py3-none-any.whl (36 kB)
      Collecting cython!=0.27,!=0.27.2,<=0.29.28,>=0.24
        Downloading Cython-0.29.28-py2.py3-none-any.whl (983 kB)
           ------------------------------------- 983.8/983.8 kB 20.7 MB/s eta 
0:00:00
      Collecting kivy_deps.gstreamer_dev~=0.3.3
        Downloading kivy_deps.gstreamer_dev-0.3.3-cp311-cp311-win_amd64.whl 
(3.9 MB)
           ---------------------------------------- 3.9/3.9 MB 35.2 MB/s eta 
0:00:00
      ERROR: Could not find a version that satisfies the requirement 
kivy_deps.sdl2_dev~=0.4.5 (from versions: 0.5.1)
      ERROR: No matching distribution found for kivy_deps.sdl2_dev~=0.4.5
      
  
  note: This error originates from a subprocess, and is likely not a problem 
with pip.
error: subprocess-exited-with-error

� pip subprocess to install build dependencies did not run successfully.
\u2502 exit code: 1
\u2570\u2500> See above for output.

note: This error originates from a subprocess, and is likely not a problem with
pip.

Installation Failed
Installing Kivy...
Error:  An error occurred while installing Kivy!
Error text: Collecting kivy
  Using cached Kivy-2.1.0.tar.gz (23.8 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'error'

  error: subprocess-exited-with-error
  
  � pip subprocess to install build dependencies did not run successfully.
  \u2502 exit code: 1
  \u2570\u2500> [10 lines of output]
      Collecting setuptools
        Using cached setuptools-66.1.1-py3-none-any.whl (1.3 MB)
      Collecting wheel
        Using cached wheel-0.38.4-py3-none-any.whl (36 kB)
      Collecting cython!=0.27,!=0.27.2,<=0.29.28,>=0.24
        Using cached Cython-0.29.28-py2.py3-none-any.whl (983 kB)
      Collecting kivy_deps.gstreamer_dev~=0.3.3
        Using cached kivy_deps.gstreamer_dev-0.3.3-cp311-cp311-win_amd64.whl 
(3.9 MB)
      ERROR: Could not find a version that satisfies the requirement 
kivy_deps.sdl2_dev~=0.4.5 (from versions: 0.5.1)
      ERROR: No matching distribution found for kivy_deps.sdl2_dev~=0.4.5
      
  
  note: This error originates from a subprocess, and is likely not a problem 
with pip.
error: subprocess-exited-with-error

� pip subprocess to install build dependencies did not run successfully.
\u2502 exit code: 1
\u2570\u2500> See above for output.

note: This error originates from a subprocess, and is likely not a problem with
pip.

Installation Failed

问题分析

  1. Python版本不匹配:工作流指定Python 3.10,但错误日志中显示下载的是cp311(Python 3.11)版本的kivy_deps.gstreamer_dev,说明实际运行环境的Python版本与指定版本不一致,导致依赖包版本不兼容。
  2. Kivy版本依赖冲突:Kivy 2.1.0要求kivy_deps.sdl2_dev~=0.4.5,但当前PyPI上该依赖的可用版本只有0.5.1,版本范围不匹配导致安装失败。

解决方案

方案1:升级Kivy版本并锁定Python版本

使用对Windows兼容性更好的Kivy 2.2.1及以上版本,该版本依赖的kivy_deps版本与最新PyPI镜像兼容,同时强制锁定Python 3.10版本:

修改后的工作流:

name: compile-source-windows

on:
  push:
    branches: [main, master]
    paths:
      - "**/src/*.py"
      - "**/src/*.bat"
      - "**/src/*.sh"
      - "**/compile-source-windows.yml"
  workflow_dispatch:

defaults:
  run:
    working-directory: "./source/01FormHelper/src/"

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: "3.10"
          allow-prereleases: false  # 禁止预发布版本,确保使用指定的Python 3.10

      - name: 升级工具并安装依赖
        run: |
          python -V
          pip install --upgrade pip setuptools wheel
          # 安装兼容Windows的Kivy版本及其他依赖
          pip install kivy==2.2.1 pyinstaller beautifulsoup4 cython

方案2:手动指定兼容的依赖版本(针对Kivy 2.1.0)

若必须使用Kivy 2.1.0,可手动指定kivy_deps.sdl2_dev版本为0.5.1,覆盖Kivy的依赖要求:

# 在安装步骤中替换为:
pip install kivy==2.1.0 kivy_deps.sdl2_dev==0.5.1 kivy_deps.gstreamer_dev~=0.3.3 pyinstaller beautifulsoup4 cython

方案3:简化依赖安装流程

避免重复安装依赖(原工作流中多次安装Kivy、cython),统一使用pip或pipenv管理,减少冲突概率。若使用pipenv,建议先初始化虚拟环境再安装:

- name: 使用pipenv安装依赖
  run: |
    python -V
    pip install --upgrade pip pipenv
    pipenv install --dev kivy==2.2.1 pyinstaller beautifulsoup4 cython

内容的提问来源于stack exchange,提问作者Prateek Raj Gautam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 11:31:06