在Python2.6虚拟环境中安装PIL时出现gcc错误

42 投票
3 回答
22203 浏览
提问于 2025-04-15 23:30

我创建了一个虚拟环境,并使用了--no-site-packages这个选项。现在我在安装PIL的时候遇到了错误:

http://pastebin.com/SVqxs1sC

...
error: command '/usr/bin/gcc' failed with exit status 1

----------------------------------------
Command /home/dustin/.virtualenvs/django1.2/bin/python -c "import setuptools; __file__='/home/dustin/.virtualenvs/django1.2/build/pil/setup.py'; execfile('/home/dustin/.virtualenvs/django1.2/build/pil/setup.py')" install --single-version-externally-managed --record /tmp/pip-t_oikl-record/install-record.txt --install-headers /home/dustin/.virtualenvs/django1.2/include/site/python2.6 failed with error code 1
Exception information:
Traceback (most recent call last):
  File "/home/dustin/.virtualenvs/django1.2/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/basecommand.py", line 120, in main
    self.run(options, args)
  File "/home/dustin/.virtualenvs/django1.2/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/commands/install.py", line 165, in run
    requirement_set.install(install_options)
  File "/home/dustin/.virtualenvs/django1.2/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/req.py", line 1243, in install
    requirement.install(install_options)
  File "/home/dustin/.virtualenvs/django1.2/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/req.py", line 540, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/home/dustin/.virtualenvs/django1.2/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/__init__.py", line 226, in call_subprocess
    % (command_desc, proc.returncode))
InstallationError: Command /home/dustin/.virtualenvs/django1.2/bin/python -c "import setuptools; __file__='/home/dustin/.virtualenvs/django1.2/build/pil/setup.py'; execfile('/home/dustin/.virtualenvs/django1.2/build/pil/setup.py')" install --single-version-externally-managed --record /tmp/pip-t_oikl-record/install-record.txt --install-headers /home/dustin/.virtualenvs/django1.2/include/site/python2.6 failed with error code 1

有人能帮我解决这个问题吗?

我正在使用Ubuntu 10.04(64位)

3 个回答

0

使用命令 sudo apt-get install python-dev 是个不错的选择,但如果你在你的系统上使用了多个 Python 版本,而默认的是 Python 2.6,那就可能会遇到一些问题。

如果你尝试这样做:

 virtualenv -p python2.7

然后进入 bin 目录,执行 source activate,接着:

pip install PIL

你可能会看到这样的错误:_imaging.c:75:20: error: Python.h: No such file or directory

你应该这样做!:

sudo apt-get install python2.7-dev
3

从你在pastebin上的完整代码来看,

_imaging.c:75:20: error: Python.h: No such file or directory

这一行是有问题的。

gcc命令行中有

-I/usr/include/python2.6

这个,所以它会在这里寻找文件,而在我的Mandriva系统上正好是这个位置。

也许你安装了python,但没有安装对应的开发库,这些库通常在软件包的“-devel”版本中。

80

你需要安装 python-dev 这个软件包。

sudo apt-get install python-dev

撰写回答