枕头模块无法正确导入

Pillow module doesn't import correctly

我正在制作一个程序,需要检查屏幕上的某个像素,检查它是什么颜色,Pillow 似乎很适合这个,但是当我尝试导入它时(是的,我做了使用 pip 安装它),我收到此错误:

ImportError: No module named Pillow

我已经尝试了所有这些导入:

import PIL
import Pillow
import pillow
from Pillow import Image
from PIL import Image
from PIL import *
from Pillow import *

但是全部return一个错误"No module named x" 当我尝试使用 PIP 安装 Pillow 时,我得到:

Requirement already satisfied: pillow in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (6.1.0)

我也使用 PIP 安装了图像:

Requirement already satisfied: pillow in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Image) (6.1.0)
Requirement already satisfied: django in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Image) (3.0.4)
Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from django->Image) (2019.3)
Requirement already satisfied: asgiref~=3.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from django->Image) (3.2.3)
Requirement already satisfied: sqlparse>=0.2.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from django->Image) (0.3.1)

如果有其他我可以使用的模块对此有好处,我会很乐意听到这些,因为它特别不需要是 Pillow,它似乎是最好用的模块。有人知道为什么这似乎无法正确导入吗?

问题的可能性太多了。您使用的是 Mac,因此您可以使用:

  • Apple 提供的 Python 2.7,没有相应的 pip 并且已过时
  • Apple 提供的 Python 3.7,确实有一个 pip
  • 自制软件 Python 3
  • homebrew Python 2 已过时

所以,您需要做的第一件事就是说 如何 启动您的 Python,因此如果您键入 python3 以启动 Python, 那么你需要提供 运行:

的输出
type python3        # or "type python" if you start Python by typing "python"

如果你输入pip3开始pip,你需要提供运行的输出:

type pip3           # or "type pip" if you start pip by typing "pip"

然后您(和我们)就会知道您打算使用什么 Python/pip 组合。一旦清楚了,您应该养成使用 shebang select 正确 Python 的习惯,因此您的脚本应该是:

#!/usr/bin/env python3
import this, that
...

例如,如果你想定位 Python3.

清楚后,正确的 import 语句是:

from PIL import Image