OSX:安装python包时出错

时间:2013-02-06 02:39:55

标签: python macos gcc installation pip

目前,由于gcc-4.0错误,我无法安装任何Python软件包。我将复制两个我正在获得的错误示例(一个使用 pip ,另一个使用手动setup.py构建/安装方法):

sgarza62$ pip install PIL
Downloading/unpacking PIL
  Running setup.py egg_info for package PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py

Installing collected packages: PIL
  Running setup.py install for PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    --- using frameworks at /System/Library/Frameworks
    building '_imaging' extension
    gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.3-fat-2.7/_imaging.o
    unable to execute gcc-4.0: No such file or directory
    error: command 'gcc-4.0' failed with exit status 1
    Complete output from command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools;__file__='/var/folders/9q/bvqtzkbx1hg1934b36zgk0y40000gp/T/pip-build/PIL/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/9q/bvqtzkbx1hg1934b36zgk0y40000gp/T/pip-nV9YEx-record/install-record.txt --single-version-externally-managed:
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py

running install

running build

running build_py

running build_ext

--- using frameworks at /System/Library/Frameworks

building '_imaging' extension

gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.3-fat-2.7/_imaging.o

unable to execute gcc-4.0: No such file or directory

error: command 'gcc-4.0' failed with exit status 1

sgarza62$ cd Imaging-1.1.7
sgarza62$ sudo python setup.py build
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.3-fat-2.7/_imaging.o
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1

以下是我将从终端复制的大量信息,希望其中一些信息有助于识别问题:

sgarza62$ gcc
i686-apple-darwin11-llvm-gcc-4.2: no input files

sgarza62$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

sgarza62$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

sgarza62$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

sgarza62$ /usr/bin/python -c 'import sys;print(sys.version)'
2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
sgarza62$ /usr/bin/python2.6 -c 'import sys; print(sys.version)'
2.6.7 (r267:88850, Jun 16 2012, 12:38:45) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
sgarza62$ /usr/bin/python2.5 -c 'import sys;print(sys.version)'
2.5.6 (r256:88840, Jun 16 2012, 12:38:24) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
sgarza62$ /usr/bin/python2.7 -c 'import sys;print(sys.version)'
2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]

以下是堆栈上的一些问题/答案,它们解决了相同或类似的问题(但这并没有为我的问题提供完整的解决方案)。也许这些先前的答案将用于解决这个问题:

Reinstalling python on Mac OS 10.6 with a different gcc version

How to use/install gcc on Mac OS X 10.8 / Xcode 4.4

Python build using wrong version of GCC on OS X


这些是我已经完成的事情,有人建议堆叠用户解决类似的问题:

  • 下载Xcode

  • 在Xcode首选项中安装命令行工具

  • sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2


我在问题上尽了最大努力,尽可能以清晰有序的方式提供尽可能多的事实。但是,如果您需要更多信息,请询问!我很乐意用更多细节编辑这个问题。

此外,我知道这似乎是一个非常具体的问题,但是从搜索中看,似乎很多人对这个问题感到困惑。

如果你不介意,我会非常感谢一个用勺子喂养的解决方案(明确说明我必须在终端中做些什么来解决这个问题)。我现在对终端不太满意了,并且对广义的答案感到有些困惑。

谢谢大家的时间,我很感激!

1 个答案:

答案 0 :(得分:4)

这里的问题是你试图在带有Xcode 4的OS X系统上使用仅32位的python.org 2.7.3。这个32位的安装程序被设计为兼容多个OS X版本可以追溯到10.3.9。不幸的是,随着Xcode 4中对PPC支持的删除以及其中的各种其他更改,安装具有C扩展模块的第三方Python软件包在10.7及更高版本的Xcode 4系统上不再开箱即用。但是,可以解决这些问题。对于PIL,通过环境变量更改几个Python Distutils默认值应该可以解决问题:

# override the default gcc-4.0 compiler and use clang instead
$ export CC=clang
# override the universal architectures to only use Intel-32
$ export ARCHFLAGS='-arch i386'
$ pip install PIL

python.org网站为当前的Python版本提供了两种OS X安装程序变体。其他安装程序提供的Python,即64位/ 32位版本,配置用于更小,更新的系统;它不支持PPC,也不会出现Xcode 4的问题。

BTW,Python 2.7(2.7.4)的下一个版本为两个安装程序提供了对Xcode 4的更好支持,并且不应该有这个问题。