python - 在 Ubuntu 中为 Python 3.1.2 安装 Pygame

标签 python ubuntu pygame

我正在阅读 Paul Craven 所著的Introduction to Computer Science Using Python and Pygame一书(注:可合法免费在线获取)。在书中,他结合使用了 Python 3.1.3 和 Pygame 1.9.1。在我的 Linux Ubuntu 机器中,我有 Python 3.1.2,但即使在我安装了 sudo apt-get python-pygame(版本 1.9.1)之后,Python 3.1.2 也无法导入 pygame。

Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pygame

然而,Python 2.6.5 可以毫不费力地导入它,

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> 

您是否知道 Linux/Ubuntu 的 Python 3.1.2 存在任何问题(Craven 教授在他的书中使用了 Windows)?为什么 Pygame 1.9.1 适用于 Python 3.1.3 但不适用于 3.1.2?

感谢您的指点。 (--,)

最佳答案

Python 3 上的 PyGame 仍处于试验阶段,但这些步骤对我在 Ubuntu 11.10 上有效:

sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev
hg clone -u 01b2cb16dc17 https://bitbucket.org/pygame/pygame
cd pygame
python3 config.py
2to3 setup.py -w
python3 setup.py build
sudo python3 setup.py install

(您可以删除 -u 01b2cb16dc17 以尝试最新版本;01b2cb16dc17 对我有用。)

关于python - 在 Ubuntu 中为 Python 3.1.2 安装 Pygame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6539472/

相关文章:

python - 如何在 plotly 中为 ticktext 着色?

python - 有没有办法为python中的每个实例创建唯一的字典属性

ubuntu - 如何在 VS Code 中启用鼠标中键单击粘贴?

python - 如何在pygame中制作保存/加载游戏功能?

python - 如何使用 SQLAlchemy Declarative ORM 在声明的属性上设置索引?

python - 删除 Pandas 中的重复项,不包括一列

python - MATLAB 生成的 Python 包与 Ubuntu 上的 PyQt5 冲突——可能是库问题

java - 如何在 Ubuntu Desktop 12.04 上设置 ANT_HOME?

python - Pygame:平铺 map 或大图像

ffmpeg - 如何精确地达到每秒 25 张图像。游戏