简体   繁体   English

为PIL构建_imaging扩展时出现gcc-4.0错误

[英]gcc-4.0 error when building _imaging extension for PIL

When I install PIL (or pillow), the _imaging C module does not install. 当我安装PIL(或枕头)时,_imaging C模块不会安装。

This is a common error, and have seen ApPeL's play-by-play solution that most have found helpful. 这是一个常见的错误,并且已经看到了ApPeL的逐个播放解决方案 ,大多数人发现这些解决方案很有帮助。 Unfortunately, when I run sudo python setup.py install , I get the following error: 不幸的是,当我运行sudo python setup.py install ,我收到以下错误:

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_LIBJPEG -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/local/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

When I run python in the shell, and try to import the modules, I get these import errors: 当我在shell中运行python,并尝试导入模块时,我收到这些导入错误:

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ 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.
>>> import PIL
>>> import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Image
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named _imaging

I've had similar errors previously, and Ned Deily has been kind enough to provide solutions . 我之前遇到过类似的错误, Ned Deily非常友好地提供解决方案 I believe my current problem may be linked to this previous question: 我相信我目前的问题可能与之前的问题有关:

OSX: error when installing Python packages (including this as reference) OSX:安装Python包时出错 (包括此参考)

Here's some other potentially useful information: 以下是其他一些可能有用的信息:

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ 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.

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ gcc
i686-apple-darwin11-llvm-gcc-4.2: no input files

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ 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

I'm not very familiar with the ins and outs if gcc, Xcode, or PIL. 如果gcc,Xcode或PIL我不熟悉这些细节。 So, if you don't mind, please provide detailed responses so that I understand how to act on your solution. 因此,如果您不介意,请提供详细的回复,以便我了解如何对您的解决方案采取行动。 Also, let me know if I can provide more details, and I will edit them into the question. 另外,如果我能提供更多详细信息,请告诉我,我会将其编辑到问题中。


EDIT: 编辑:

I've installed pillow with pip, as suggested by MattDMo , Image now imports successfully, but _imaging does not (I believe the c extensions aren't being properly compiled by gcc on my machine, see above): 我已经按照MattDMo的建议安装了pip pillowImage现在导入成功,但是_imaging没有(我相信我的机器上的gcc没有正确编译c扩展,见上文):

Santiagos-MacBook-Air:riotry_mobile sgarza621$ 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.
>>> import Image
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_imaging.so
  Expected in: dynamic lookup

I'm using PIL to process images on a Django web app, and I get the following error when I try to upload an image through a form for processing by PIL: 我正在使用PIL在Django Web应用程序上处理图像,当我尝试通过表单上传图像以供PIL处理时,我收到以下错误:

The _imaging C module is not installed

SECOND EDIT: 第二次编辑:

Here's more information, related to the python and gcc, which I hope will shed light on the problem: 这里有更多关于python和gcc的信息,我希望能够解释这个问题:

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ /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)]
$ /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)]

Many if not all of your problems (hopefully) can be solved by using Pillow instead. 如果不是所有的问题(希望)都可以通过使用Pillow来解决。 PIL development was just kind of halted a while back, and unfortunately the code wasn't forwards-compatible in any way, so as compilers and Python matured, errors crept in. The Pillow fork is stable, actively developed, and pretty widespread, so you can feel safe using it. PIL开发只是暂时停止了一段时间,不幸的是代码在任何方面都没有向前兼容,所以随着编译器和Python的成熟,错误也随之而来。枕头分支稳定,积极开发,并且非常普遍,所以你可以放心使用它。 Version 2.0 has a bunch of enhancements, including Python 3 support. 2.0版有许多增强功能,包括Python 3支持。 You'll have to use from PIL import Image instead of import Image , though. 但是,您必须使用from PIL import Image而不是import Image Good luck! 祝好运!

Wow. 哇。 I hope this helps people who have the same problem in the future, because that was brutal. 我希望这可以帮助将来遇到同样问题的人,因为那是残酷的。

The solution was to install the python.org 64-bit/32-bit installer for Mac, as outlined in Ned Deily's answer to the question “…can't figure out the architecture type of…” problem when compiling Python C-extension with gcc . 解决方案是python.org 64-bit/32-bit installer适用于Mac的python.org 64-bit/32-bit installer ,如Ned Deily 在编译Python C-extension时问题“...无法弄清楚......的体系结构类型”问题中所述。 gcc

First, I made sure that the default python was this new python (just by running python in the shell). 首先,我确保默认的python是这个新的python(只是在shell中运行python )。

Then, I reinstalled pip , and ran pip install PIL . 然后,我重新安装了pip ,然后运行pip install PIL And that did it! 就这样做了!

Just to make sure, I opened up python in the shell, and imported the three modules: 为了确保,我在shell中打开了python,并导入了三个模块:

>>> import PIL
>>> import Image
>>> import _imaging

All of them (finally) imported without errors. 所有这些(最后)导入没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM