【问题标题】:how to install PIL on python shell on OS X 10.9.5如何在 OS X 10.9.5 上的 python shell 上安装 PIL
【发布时间】:2016-08-24 23:05:43
【问题描述】:

我是 Python 新手。 我尝试使用 Python 3.5.2 shell 安装 PIL。 我首先将pip install PIL 输入到python 解释器中。它没有用,向我展示了这个:SyntaxError: invalid syntax

然后我在网上搜索并尝试了这个:pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL。仍然是语法错误。

最后我尝试了这个:install PIL 也没有工作。

我想知道shell命令是否与终端命令不同?我目前正在使用 OS X 10.9.5,如果我使用终端编写 python,它将是 Python 2.7.X,因为它与某些系统文件有关,所以我无法更改它。 我想问如何使用 Python shell 安装 PIL 或其他模块?

这个问题与“如何安装 PIL”相关的其他问题不同。我想问如何使用 Python 3.5 shell 来安装 PIL。如果我使用终端命令安装 PIL,那么它将安装到我的系统默认 python 中,即 Python 2.7.X。

【问题讨论】:

  • Installing PIL with pip的可能重复
  • 我想有人回答了你的问题here
  • 还有here
  • 这些问题通常与安装 PIL 相关;这个问题是关于在 Python 2.7 安装了 pip 后,如何在 Python 3.5 中使用 pip 安装 PIL。
  • 您是如何安装 Python 2.7 和 3.5 的副本的?你只使用 Python 3.5 还是 2.7?您可能应该让 pip 使用 Python 3.5 而不是 2.7,但最好的方法取决于您对这些问题的回答。

标签: python macos shell


【解决方案1】:

您应该从系统终端(BASH 提示符)运行pip 命令,而不是从 Python 内部。通常你会打开/Applications/Utilities/Terminal.app,然后输入pip install PIL。如果安装的是 Python 2.7 而不是 3.5 的包,您可以试试这个:python3 $(which pip) install PIL

或者在 Python 3.5 中你可以试试这个(来自Installing python module within code):

import pip
pip.main(['install', 'PIL'])

一个长期的解决方案是安装 pip 以使用 Python 3.5 而不是 2.7。为此,您可以从系统终端运行以下命令:

curl --remote-name https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

那么pip install PIL 应该在你的 3.5 安装中安装 PIL。

【讨论】:

  • 您应该考虑使用Pillow 而不是“旧”PIL 库。
  • 它向我显示了这个错误:“找不到满足 PIL 要求的版本(来自版本:)没有找到 PIL 的匹配分布”所以我尝试了枕头,它可以工作。谢谢你们俩!我很欣赏你的具体回答! @mfripp
【解决方案2】:
pip install pillow

pillow 是旧的PIL 包的包装器,它的作用就像一个魅力。

【讨论】:

    猜你喜欢
    • 2014-11-19
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多