繁体   English   中英

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

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

当我安装PIL(或枕头)时,_imaging C模块不会安装。

这是一个常见的错误,并且已经看到了ApPeL的逐个播放解决方案 ,大多数人发现这些解决方案很有帮助。 不幸的是,当我运行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

当我在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

我之前遇到过类似的错误, Ned Deily非常友好地提供解决方案 我相信我目前的问题可能与之前的问题有关:

OSX:安装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.

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

如果gcc,Xcode或PIL我不熟悉这些细节。 因此,如果您不介意,请提供详细的回复,以便我了解如何对您的解决方案采取行动。 另外,如果我能提供更多详细信息,请告诉我,我会将其编辑到问题中。


编辑:

我已经按照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

我正在使用PIL在Django Web应用程序上处理图像,当我尝试通过表单上传图像以供PIL处理时,我收到以下错误:

The _imaging C module is not installed

第二次编辑:

这里有更多关于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)]

如果不是所有的问题(希望)都可以通过使用Pillow来解决。 PIL开发只是暂时停止了一段时间,不幸的是代码在任何方面都没有向前兼容,所以随着编译器和Python的成熟,错误也随之而来。枕头分支稳定,积极开发,并且非常普遍,所以你可以放心使用它。 2.0版有许多增强功能,包括Python 3支持。 但是,您必须使用from PIL import Image而不是import Image 祝好运!

哇。 我希望这可以帮助将来遇到同样问题的人,因为那是残酷的。

解决方案是python.org 64-bit/32-bit installer适用于Mac的python.org 64-bit/32-bit installer ,如Ned Deily 在编译Python C-extension时问题“...无法弄清楚......的体系结构类型”问题中所述。 gcc

首先,我确保默认的python是这个新的python(只是在shell中运行python )。

然后,我重新安装了pip ,然后运行pip install PIL 就这样做了!

为了确保,我在shell中打开了python,并导入了三个模块:

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

所有这些(最后)导入没有错误。

暂无
暂无

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

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