Pillow已安装,但仍然得到" ImportError:没有名为PIL的模块"

时间:2018-05-10 11:27:25

标签: python macos pillow

我确实发现这个问题被更多的人问了,但是没有一个人完全符合我的情况,所以我自己在这里问。 我在Mac上运行最新的MacOS High Sierra,有两个版本的Python(2.7和3.4.3)。据我了解,v2.7是MacOS的默认安装。我安装了3.4.3(从python站点下载的.dmg文件)。因此,现在,python命令默认为2.7,而python3指向终端中的3.4.3。 在尝试学习的过程中,我尝试了一个使用

的python脚本

import PILfrom PIL import Image

但是在运行时,会出现错误ImportError: No module named PIL。 通过对谷歌的研究,我想出了使用

安装PIL和Pillow

sudo pip install Pillow

安装正确,但我仍然遇到同样的错误。 为了消除这种混淆,我决定从系统中删除python 3.4.3。但即使它被删除,我仍然会得到同样的错误。 即使pip list显示Pillow 5.1.0也可以。 所以现在,我只使用Python 2.7,错误仍然存​​在,而Pillow也在那里。

which python/opt/local/bin/python作为路径。

以上任何一个响铃吗?任何想法,还有什么可以在这里失踪?

3 个答案:

答案 0 :(得分:1)

Phew,终于找到了这个问题。谢谢@Yash指点。 顺便说一句,我做了一个Array.prototype.slice.call(document.querySelectorAll('img[alt="Apple Store Logo"]')).forEach(function (img) { img.parentNode.removeAttribute('target'); }); ,并且令人惊讶地得到了这个输出:

which -a python

该死的,我不记得我在/opt/local/bin/python /usr/bin/python 文件夹上安装了第二个2.7版本(可能是通过macports)。好吧,删除了混乱,删除了这个python,所以现在我只留下系统在/opt/local/bin安装了python。 现在进口全部按预期完美运行。 : - )

答案 1 :(得分:0)

基本安装:

    final String messageName = inputBox("Create New Message",
            "Message Name");

    if (messageName == null)
        return null;
    String camel = camelCase(messageName);
    final String methodName = "handle" + camel;

    IType type = null;
    try {
        unit.createImport(Global.WHEN_RECEIVED_CLASS_NAME.<String>data(), null, null);
        type = unit.getType(drop(unit.getElementName(), 4));

        if (!type.getSuperclassName().equals("SimpleAgent")) {
            msgbox("cannot create message - unrecognized agent type");
            return null;
        }

        IMethod mtd = method(type, methodName);

        if (mtd == null) {
            mtd = type
                    .createMethod(
                            "@WhenReceived(\""
                                    + messageName
                                    + "\")\npublic void "
                                    + methodName
                                    + "(){\n\t//TODO: Add Message Handling Code Here.\n\t"
                                    + "//you can add any parameters to the method in order to receive them within the message.\n}\n",
                            null, false, null);
        }

        CompilationUnitEditor editor = activeCompilationUnitEditor();
        editor.setSelection(mtd);

Windows安装:

pip install Pillow

参考:https://pillow.readthedocs.io/en/stable/installation.html

答案 2 :(得分:0)

试试这个。它对我有用

pip install --upgrade --force-reinstall pillow

如果您收到类似拒绝访问错误的信息,请运行以下命令

pip install --upgrade --force-reinstall pillow --user
相关问题