当我安装 PIL(或枕头)时,_imaging C 模块没有安装。
这是一个常见错误,并且已经看到了 AppPeL 的逐个播放解决方案,大多数人都认为它很有帮助。不幸的是,当我运行时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 的来龙去脉不是很熟悉。因此,如果您不介意,请提供详细的回复,以便我了解如何对您的解决方案采取行动。另外,如果我可以提供更多详细信息,请告诉我,我会将它们编辑到问题中。
编辑:
我已经按照MattDMopillow
的建议安装了 pip,现在可以成功导入,但没有成功(我相信我的机器上的 gcc 没有正确编译 c 扩展,见上文):Image
_imaging
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)]