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

Ubuntu16.04下Anaconda3 Python3.5.4环境安装Kivy失败求助

Fixing Kivy Installation Failures Due to Missing SDL2 Libraries in Conda Environment

Hey there, I’ve dealt with this exact headache before when setting up Kivy in a Conda environment on Ubuntu! The issue here is that even though you installed the system-level dependencies as per the Kivy docs, your isolated Conda environment isn’t picking up those system libraries during the pip compilation process. Let’s walk through the fixes step by step:

Step 1: Verify & Install SDL2 Development Libraries

First, double-check that you have all the required SDL2 development packages installed (the linker needs these, not just the runtime versions). Run this command to install or confirm them:

sudo apt-get update && sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev

This ensures the linker can find the -lSDL2 family of libraries it’s complaining about.

Step 2: Tell Conda Where to Find System Libraries

Conda environments are designed to be isolated, so they don’t automatically use system-wide library paths by default. We need to set environment variables to point the compiler to the right locations:

  1. Activate your Conda environment first:

    source activate building
    
  2. Export the required flags to let pip’s compilation process locate the SDL2 headers and libraries:

    export CFLAGS="-I/usr/include/SDL2"
    export LDFLAGS="-L/usr/lib/x86_64-linux-gnu"
    

    Note: If you’re on a 32-bit system, replace x86_64-linux-gnu with i386-linux-gnu.

    To make this permanent (so you don’t have to export these every time), create an environment variable script in your Conda environment:

    • Navigate to your environment’s activate.d directory:
      mkdir -p $CONDA_PREFIX/etc/conda/activate.d
      
    • Create a file called env_vars.sh with the export commands:
      echo 'export CFLAGS="-I/usr/include/SDL2"' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
      echo 'export LDFLAGS="-L/usr/lib/x86_64-linux-gnu"' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
      

    Next time you activate the environment, these variables will load automatically.

Step 3: Reinstall Cython & Kivy

First, clean up any partial installations from your previous attempts:

pip uninstall -y cython kivy

Then reinstall in the correct order:

pip install cython==0.25.2
pip install kivy

Alternative: Use Conda-Forge for Kivy (No Compilation Needed)

If the above steps still give you trouble, skip the pip compilation entirely and use Conda’s pre-built packages from conda-forge. This handles all dependencies automatically:

source activate building
conda install -c conda-forge kivy

Why This Happens

When you install Kivy via pip, it compiles the library from source, which requires linking against the SDL2 development libraries. Conda’s isolation means it doesn’t look in system paths by default, so we have to explicitly tell the compiler where to find those files. Using conda-forge avoids this because it packages all required dependencies within the Conda ecosystem.

内容的提问来源于stack exchange,提问作者Akash Jobanputra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:59:06