![在 12.04 上安装 pygame](https://linux22.com/image/838388/%E5%9C%A8%2012.04%20%E4%B8%8A%E5%AE%89%E8%A3%85%20pygame.png)
按照说明操作后如何在 virtualenv 中安装 Pygame?现在运行‘pip install pygame’将返回:
Downloading/unpacking pygame
Running setup.py egg_info for package pygame
Skipping module _numericsurfarray for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module _numericsndarray for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module scrap for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module _camera for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
warning: no files found matching 'readme.txt'
no previously-included directories found matching '*/CVS'
no previously-included directories found matching '*/*/CVS'
Installing collected packages: pygame
Running setup.py install for pygame
Skipping module _numericsurfarray for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module _numericsndarray for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module scrap for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module _camera for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
building 'pygame.imageext' extension
gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC -D_REENTRANT -I/usr/X11R6/include -I/usr/include/SDL -I/usr/include/SDL -I/usr/include -I/usr/include -I/usr/include/python3.2mu -c src/imageext.c -o build/temp.linux-x86_64-3.2/src/imageext.o
In file included from src/imageext.c:47:0:
src/pygame.h:75:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /home/david/.virtualenvs/pywork3/bin/python3.2 -c "import setuptools;__file__='/home/david/.virtualenvs/pywork3/build/pygame/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-0tu3l3-record/install-record.txt --install-headers /home/david/.virtualenvs/pywork3/include/site/python3.2:
Skipping module _numericsurfarray for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module _numericsndarray for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module scrap for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
Skipping module _camera for Python 3.2.3 (default, Apr 10 2013, 06:11:55)
[GCC 4.6.3] build.
running install
running build
running build_py
running build_ext
building 'pygame.imageext' extension
gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC -D_REENTRANT -I/usr/X11R6/include -I/usr/include/SDL -I/usr/include/SDL -I/usr/include -I/usr/include -I/usr/include/python3.2mu -c src/imageext.c -o build/temp.linux-x86_64-3.2/src/imageext.o
In file included from src/imageext.c:47:0:
src/pygame.h:75:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /home/david/.virtualenvs/pywork3/bin/python3.2 -c "import setuptools;__file__='/home/david/.virtualenvs/pywork3/build/pygame/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-0tu3l3-record/install-record.txt --install-headers /home/david/.virtualenvs/pywork3/include/site/python3.2 failed with error code 1 in /home/david/.virtualenvs/pywork3/build/pygame
Storing complete log in /home/david/.pip/pip.log
有什么想法吗?
答案1
fatal error: Python.h: No such file or directory
这表明你还没有安装 Python 开发(头文件)包。对于 Python 2.7(默认),它包含在python-dev,对于你使用的 Python 3.2 版本来说,这是python3.2-dev
。请注意,只有从 Ubuntu 软件包安装了 Python 3.2 后,此功能才会起作用。
安装后,再次尝试安装 Python 包。
这新错误你得到的,
error: could not create '/usr/local/lib/python3.2/dist-packages/pygame': Permission denied`
可能有两个原因:
您没有在 Python 虚拟环境中工作。如果不在虚拟环境中工作,它将尝试安装在系统文件夹(
/usr/local/
等等)中。解决方案:正确切换到虚拟环境,例如,在同一终端窗口中workon <virtualenvname>
运行命令。pip
或者,如果您不打算使用虚拟环境:
您正在尝试在系统范围内安装它,但您没有提升权限来执行此操作。解决方案:
pip
在命令前面添加sudo
,例如sudo pip install pygame