为什么 Python 在 2019 年无法从 PIL 导入图片?



我的问题与 为什么 Python 不能从 PIL 导入图像? 但是5年来发生了很多变化。 我正在使用python 3.7.3,我也在使用pyenv. 我最终想使用解释器pypy但我必须先解决这个问题。 当我不使用pyenv时,我有pillowPIL工作,我正在使用3.6但不再使用。 本质上,当我使用 Pycharm 运行 Python 时

from PIL import Image

我得到:

Traceback (most recent call last):
File "/Users/kylefoley/.pyenv/versions/3.7.3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-4dba96fe377b>", line 1, in <module>
from PIL import ImageColor
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/kylefoley/.pyenv/versions/3.7.3/lib/python3.7/site-packages/PIL/ImageColor.py", line 20, in <module>
from . import Image
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/kylefoley/.pyenv/versions/3.7.3/lib/python3.7/site-packages/PIL/Image.py", line 56, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/Users/kylefoley/.pyenv/versions/3.7.3/lib/python3.7/site-packages/PIL/__init__.py)

当我从终端运行 Python 时,我得到

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kylefoley/.pyenv/versions/3.7.3/lib/python3.7/site-packages/PIL/Image.py", line 56, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/Users/kylefoley/.pyenv/versions/3.7.3/lib/python3.7/site-packages/PIL/__init__.py)

如果你看一下第 56 行的Image.py模块,它说:

# should match _PyUnicodeUCS4_FromString and
# _PyUnicodeUCS4_AsLatin1String
warnings.warn(
"The _imaging extension was built for Python with UCS4 support; "
"recompile Pillow or build Python --with-wide-unicode. ",
RuntimeWarning
)
# Fail here anyway. Don't let people run with a mostly broken Pillow.
# see docs/porting.rst

我不知道该怎么办。 我也尝试了这里推荐的解决方案 为什么 Python 不能从 PIL 导入图像? 它们来自 5 年前,其中许多面向 Linux 并且不起作用。

我最终通过使用安装程序解决了这个问题miniconda3。 其他人向我展示了如何安装miniconda3所以不幸的是,我不能提供比这更多的帮助,因为他做得如此之快,以至于我已经忘记了他是怎么做到的。

最新更新