【问题标题】:Can't install PIL after Mac OS X 10.9Mac OS X 10.9 后无法安装 PIL
【发布时间】:2013-11-01 03:57:25
【问题描述】:

我刚刚将我的 Mac OS 更新到 10.9,我发现我的一些(全部?) Python 模块不再存在,尤其是 Image 模块。

所以我尝试执行sudo pip install pil,但我得到了这个错误:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found

#      include <X11/Xlib.h>

               ^

1 error generated.

error: command 'cc' failed with exit status 1

我的 Xcode 是最新的,我不知道。 PIL 可能还不兼容 10.9 吗?

【问题讨论】:

  • 不是答案,但你试过枕头吗? pypi.python.org/pypi/Pillow/2.2.1 - PIL 得到了很好的支持。
  • @JamesAddison Pillow 2.2.1 也同样有效。
  • 你想要pip install pillow
  • 在 macos 10.10.5 Yosemite 上,pip install Pillow==5.0.0 工作,安装 .../site-packages/PIL。 (为什么是 5.0.0?见issue)。

标签: python macos python-imaging-library pip osx-mavericks


【解决方案1】:

我已从 pyenv 移动到 virtualenv,这解决了我的问题。

【讨论】:

    【解决方案2】:

    在 Mac OSC 10.10 Yosemite 上安装 PIL (Imaging.1.1.7)。我尝试了这里推荐的许多修复,但每一个都遇到了麻烦。我终于通过编辑 setup.py 文件解决了这个问题:

    TCL_ROOT = "/opt/X11/include"

    它在 _imagingtk.c 的编译中传递了 X11 的适当包含路径,这对我来说是个问题。更改后立即工作。

    【讨论】:

      【解决方案3】:

      为我工作(OS X Yosemite 10.10.2 - Python 2.7.9):

      xcode-select --install
      sudo pip install pillow
      

      试试这个来检查它:

      from PIL import Image
      image = Image.open("file.jpg")
      image.show()
      

      【讨论】:

        【解决方案4】:

        执行下面的命令行。在 Mac OS 10.9.5 上像魅力一样工作

        easy_install pip

        sudo pip install setuptools --no-use-wheel --upgrade

        sudo pip install Pillow

        最好, 西奥

        【讨论】:

          【解决方案5】:
          sudo pip uninstall pillow
          pip install pillow
          

          为我工作。我在 Yosemite 上运行 Python 2.7.9。import PIL 现在适合我。

          【讨论】:

            【解决方案6】:

            我不想安装 XCode(我不使用它)并且我不愿意摆弄 Application 目录。我从这篇文章中的许多答案中抄袭下来,以下两个步骤适用于 10.9.5:

            sudo easy_install pip
            sudo pip install pillow
            

            在我看来,我必须使用 easy_install 来安装 pip 确实很奇怪。但是在(重新)安装之前,pip 不想为我工作。

            【讨论】:

              【解决方案7】:

              这就是我所做的,有些步骤可能不是仅用于 PIL,但无论如何我需要 libpng 和其他步骤:

              1) 运行 xcode install,使用此命令或从应用商店下载更新:

              xcode-select --install
              

              1b) 添加命令行工具可选工具,在 Mountain Lion 中,这是 xcode 下载页面上的一个选项,但现在您必须使用您的 Apple id 注册并从以下地址下载:https://developer.apple.com/downloads/

              寻找 Xcode 的命令行工具(OS X Mavericks)

              2)安装python所需的一切(使用brew),我相信你也可以使用port:

              brew install readline sqlite gdbm
              brew install python --universal --framework 
              brew install libpng jpeg freetype
              

              如果需要取消链接/重新链接,例如升级。

              3) 安装 Pip 和所需模块:

              easy_install pip 
              sudo pip install setuptools --no-use-wheel --upgrade
              

              4) 最后,这没有错误:

              sudo pip install Pillow
              

              更新 11/04/14:PIL 存储库不再接收更新或支持,因此应使用 Pillow。以下内容现已弃用,因此请坚持使用 Pillow。

              sudo pip install pil --allow-external pil --allow-unverified pil
              

              更新(旧):安装 Pillow(PIL fork)时同样适用,并且应该提到它在大多数 PIL 情况下迅速成为替代品。不要在第 4 步中安装 pip,而是运行以下命令:

              sudo pip install Pillow
              

              希望这对某人有所帮助!

              【讨论】:

              • 第 4 步)可能以 _imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found 之类的东西结束。但可以通过stackoverflow.com/questions/20325473/…解决。
              • 你是安装pil还是枕头? PIL 已弃用,我会更新它。
              • 没关系。 PIL 或 Pillow,对于某些人来说解决符号链接 freetype/freetype2 问题可能仍然有用。不过谢谢!
              • 是的,我在第 2 步中添加了一些内容,以便在升级时取消链接 /link。如果缺少某些内容,您可以编辑我会接受吗?
              • sudo pip install pil --allow-external pil --allow-unverified pil 在 2015 年帮助了我
              【解决方案8】:

              试试这个:

              ln -s /usr/local/include/freetype2 /usr/local/include/freetype
              

              【讨论】:

              • 请多补充一点,并解释他为什么要这样做。
              【解决方案9】:
              ln -s /usr/local/include/freetype2 /usr/local/include/freetype
              sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pil
              

              【讨论】:

                【解决方案10】:

                改为安装Pillow

                sudo pip install pillow
                

                【讨论】:

                • 您仍然需要像 PIL 一样的所有预配置
                • @radtek 不,你不在 mac 10.9 上。在否决我的答案之前,您是否真的尝试过该命令?
                • 我没有否决你的答案,我投了赞成票,但我确实尝试过。我实际上已经这样做了几次,实际上我不需要步骤 1b,但我需要其他所有东西。
                【解决方案11】:

                我最近从 OS 10.8 升级的机器 -> 10.9 卡在 xcrun 和 lipo 之间的循环中。

                将 /usr/bin/lipo 重命名为 /usr/bin/lipo_broken

                有关如何解决的更多信息,请参阅此主题:

                xcrun/lipo freezes with OS X Mavericks and XCode 4.x

                【讨论】:

                  【解决方案12】:

                  由于接受的答案是xcode-select --install 的正确答案,但有些人(包括我)可能会遇到Can't install the software because it is not currently available from the Software Update server 如果您使用的是 beta 软件(因为我现在使用的是 Yosemite 并且遇到了同样的问题),您需要单独获取 CLT,因为它不包含在 XCode 中(甚至是 xcode beta) 前往developers.apple.com 获取适用于您操作系统的CLT 工具;)

                  附:你不需要 XQuartz 来让 PIL 或 Pillow 工作

                  【讨论】:

                    【解决方案13】:

                    我遇到了以下错误

                    building 'PIL._imagingft' extension
                    _imagingft.c:62:10: fatal error: 'freetype/fterrors.h' file not found
                    
                    #include <freetype/fterrors.h>
                    
                             ^
                    
                    1 error generated.
                    
                    error: command 'cc' failed with exit status 1
                    

                    解决方案是将 freetype2 符号链接到 freetype,这解决了问题。

                    【讨论】:

                      【解决方案14】:

                      确保您的 xcode 上安装了命令行工具。然后执行:

                      sudo pip install pil --allow-external pil --allow-unverified pil
                      

                      【讨论】:

                      • 我能够在没有命令行工具的情况下使用 Xcode for Mavericks 安装它。
                      【解决方案15】:

                      这些都不适合我。我一直收到:

                      clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
                      clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
                      error: command 'cc' failed with exit status 1
                      

                      所以我找到了以下解决方案的解决方法:

                      sudo export CFLAGS=-Qunused-arguments
                      sudo export CPPFLAGS=-Qunused-arguments
                      sudo pip install PIL --allow-external PIL --allow-unverified PIL
                      

                      这样我就可以安装了。

                      【讨论】:

                      • 这是为我修复它的那个。如果您正在运行虚拟环境,则不需要 sudo 命令。
                      • 谢谢!这适用于运行 Python 虚拟环境。我目前没有安装 Xcode,所以这节省了我的下载时间。
                      • 这适用于 10.8 中的旧 xcode,它适用于 Mavericks 吗?
                      【解决方案16】:

                      更完整的解决方案需要安装 Xquartz X11 子系统,该子系统已在 Apple 之外构建了数年。以下是我用来完成所有工作的步骤

                      1. http://xquartz.macosforge.org/landing/ 安装 XQuartz
                      2. 运行sudo pip install pillow

                      【讨论】:

                        【解决方案17】:

                        我也遇到过类似的问题:用clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]安装枕头失败,用Can't install the software because it is not currently available from the Software Update server.安装命令行工具失败,甚至手动安装命令行工具后,编译PIL失败。

                        发生这种情况的原因是,最新版本的 xcode 下的 clang 不会对未知的编译器标志发出警告,而是会以硬错误停止编译。

                        要解决此问题,只需在尝试编译(安装 pil)之前在终端上运行 export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"

                        【讨论】:

                          【解决方案18】:

                          您可以使用 Homebrew 进行安装 http://brew.sh

                          brew tap Homebrew/python
                          brew install pillow
                          

                          【讨论】:

                          • 你好 rchapman。当我运行 brew 来安装 samueljohn/python/pillow 时,它会给出如下警告:pillow-2.5.1 already installed, it's just not linked。在此之前,有 15 个警告,例如:Could not tap homebrew/python/cpyrit-cuda over samueljohn/python/cpyrit-cuda。任何想法为什么会发生这种情况?或者我怎样才能链接枕头?
                          【解决方案19】:

                          这是我在 mac os 10.9.1 上的步骤

                          1. sudo su
                          2. easy_install pip
                          3. xcode-select --install
                          4. pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
                          

                          【讨论】:

                            【解决方案20】:

                            简单运行

                            pip install pil --allow-external pil --allow-unverified pil

                            【讨论】:

                              【解决方案21】:

                              重复使用@DmitryDemidenko 的答案,这对我有用:

                              ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
                              

                              然后

                              sudo pip install -U PIL --allow-external PIL --allow-unverified PIL
                              

                              【讨论】:

                                【解决方案22】:

                                以下对我有用:

                                ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
                                sudo pip install pil
                                

                                更新:

                                但下面有更正确的解决方案,由 Will 提供。

                                打开终端并执行: xcode-select --install

                                【讨论】:

                                • 您的回答有误,是MacOS10.9.sdk 而不是MacOS0.9.sdk
                                • 如果您还想拥有一个支持 zlib/png/zip 的 PIL/Pillow,您还需要这样做:ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/zlib.h /usr/local/include/
                                • 建议的命令会从 Apple 弹出一个错误对话框。首先它询问我是要获取 XCode(我拥有)还是“安装”。我选择安装。它弹出一个 EULA,我接受,然后出现一个错误对话框:“无法安装该软件,因为它当前无法从软件更新服务器获得。”
                                • 遇到错误Downloading/unpacking pil Could not find any downloads that satisfy the requirement pil Some externally hosted files were ignored (use --allow-external pil to allow). Cleaning up... No distributions at all found for pil Storing debug log for failure in /Users/Usermania/.pip/pip.log
                                • ln: /usr/local/include/X11: No such file or directory 我没有 /usr/local/include/X11 目录?
                                【解决方案23】:

                                打开你的终端并执行:

                                xcode-select --install

                                【讨论】:

                                • 问题不在于安装 Xcode 而是 PIL ......此外,我解释说我已经安装了 Xcode 并且是最新的。
                                • 这也解决了问题(它安装了Xcode默认未安装的命令行工具)。
                                • 这就是我需要做的所有事情,没有那些符号链接的东西。
                                • @VincentShowcaseWorkshop Xcode 默认不安装命令行工具。我必须这样做才能解决与 OP 相同的问题,尽管我肯定已经安装了 Xcode 并且在 Mac OS 10.9.2 上是最新的。
                                • 这修复了 Mac 版本 10.11.2 (15C50) 的问题。
                                【解决方案24】:

                                这就是我所做的:

                                首先升级到 Xcode 5(我运行的是 10.9)。然后,在终端中执行以下命令:

                                $ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
                                $ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 usr/include/
                                

                                【讨论】:

                                • 两周前给出并接受了类似的答案。我看不到你的附加价值......
                                • 好吧,这个答案的路径与接受的路径不同。我将此版本添加为对已接受答案的评论。命令是sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/X11
                                【解决方案25】:
                                sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/ /usr/local/include/X11
                                

                                对我有帮助! 操作系统 x 10.9

                                pip install pillow
                                

                                但是! pip安装后...

                                *** ZLIB (PNG/ZIP) support not available
                                

                                最后我通过运行来修复它:

                                xcode-select --install
                                

                                然后重新安装枕头

                                pip install pillow
                                
                                PIL SETUP SUMMARY
                                    --------------------------------------------------------------------
                                    version      Pillow 2.2.1
                                    platform     darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
                                                 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
                                    --------------------------------------------------------------------
                                    --- TKINTER support available
                                    --- JPEG support available
                                    --- ZLIB (PNG/ZIP) support available
                                    --- TIFF G3/G4 (experimental) support available
                                    --- FREETYPE2 support available
                                    --- LITTLECMS support available
                                    --- WEBP support available
                                    --- WEBPMUX support available
                                    --------------------------------------------------------------------
                                

                                【讨论】:

                                • 昨天更新到小牛,就在今天我开始了一个项目,你帮我省了几个小时的心痛谢谢!
                                • 这是我必须做的 $> ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install枕头
                                • 谢谢!对于 10.10 使用:sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers /X11 /usr/local/include/X11
                                【解决方案26】:

                                安装命令行工具为我解决了这个问题

                                您必须单独安装它们,因为它们现在不是 xcode 中软件包的一部分:

                                https://developer.apple.com/downloads/index.action?=command%20line%20tools#

                                【讨论】:

                                • 我绝对喜欢这种方法。我讨厌使用系统包进行自定义符号链接......你永远不知道下一次更新会发生什么......
                                • 这似乎是一个错误的 URL。
                                • @MattFeifarek 该 URL 今天对我有用。我必须使用开发帐户登录,但随后我进入了相关的命令行工具下载页面。
                                【解决方案27】:
                                1. ln -s /opt/X11/include/X11 /usr/local/include/X11
                                2. 不带 sudo 的 pip install pil

                                【讨论】:

                                  【解决方案28】:

                                  找到解决方案...您必须像这样ln -s /opt/X11/include/X11 /usr/local/include/X11 对 X11 进行符号链接,然后 sudo pip install pil 应该可以工作。

                                  【讨论】:

                                  • 不适合我...您在使其工作之前更新了您的 xcode 吗?你重启你的mac很多次了吗?这让我很沮丧。呃。
                                  • 我之前进行了 xcode 更新,即使我不确定它是否有用,我也重新启动了我的 mac。也许你的 X11 的路径对你来说是不一样的。试试其他一些答案吧。
                                  猜你喜欢
                                  • 2014-04-29
                                  • 2013-11-02
                                  • 2014-03-20
                                  • 2014-02-12
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2013-11-11
                                  • 2013-11-17
                                  相关资源
                                  最近更新 更多