适配64位Kivy:MacBook Pro下安装64位Pygame的解决方案
Hey there, let's work through this compatibility issue between your 64-bit Kivy setup and the 32-bit Pygame installation on your MacBook Pro running macOS 10.12.1. Since switching to 32-bit Python isn't an option for your other modules, here are three targeted solutions:
1. Compile a 64-bit Version of Pygame from Source
This is the most direct way to get a Pygame build that matches your 64-bit Python environment. Here's how to do it:
- First, install the required dependencies using Homebrew (if you don't have Homebrew installed, set it up first):
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi - Download the source code for a Pygame version compatible with macOS 10.12.1 (I recommend 1.9.6 as newer versions may drop support for older macOS releases).
- Extract the source archive, navigate to the folder in Terminal, and run:
python configure.py --enable-64bit make && sudo make install - Verify the installation by running
python -c "import pygame; print(pygame.__version__)"—if it runs without errors, you've got a working 64-bit build.
2. Switch Kivy to Use SDL2 Backends (Avoid Pygame Entirely)
Kivy doesn't strictly require Pygame; it supports SDL2 as an alternative backend for graphics and audio. This lets you bypass the 32-bit Pygame issue entirely:
- Add these lines at the very top of your Kivy application code to force SDL2 usage:
from kivy.config import Config # Set graphics backend to SDL2 Config.set('graphics', 'backend', 'sdl2') # Set audio backend to SDL2 Config.set('audio', 'backend', 'sdl2') - Alternatively, you can permanently update your Kivy config file (
~/.kivy/config.ini) by modifying the[graphics]and[audio]sections to usesdl2instead ofpygame. - Since your Kivy installation is already 64-bit, the SDL2 components bundled with it will also be 64-bit, so this should work seamlessly.
3. Use a 64-bit Virtual Environment for Clean Installation
System-wide Python environments can have conflicting 32/64-bit packages. Creating a dedicated 64-bit virtual environment ensures you install only compatible versions:
- If using
virtualenv:# Create a 64-bit virtual environment virtualenv --python=/usr/bin/python3 kivy64_env # Activate the environment source kivy64_env/bin/activate # Install 64-bit Kivy and Pygame pip install kivy pygame==1.9.6 - If using Conda (great for managing binary dependencies):
# Create a 64-bit environment with Python 3.7 (compatible with macOS 10.12.1) conda create -n kivy64_env python=3.7 conda activate kivy64_env # Install Kivy and Pygame conda install -c conda-forge kivy pygame - Always run your Kivy app from within this activated environment to ensure you're using the 64-bit packages.
Quick Notes
- macOS 10.12.1 is an older release, so stick to older, compatible versions of Pygame/Kivy (like Pygame 1.9.6 and Kivy 1.11.x) to avoid compatibility issues.
- If you run into compilation errors with Pygame, double-check that all Homebrew dependencies are installed and that you're using the system's 64-bit Python executable.
内容的提问来源于stack exchange,提问作者Boi

