python-imaging-library - 显示 ImportError : cannot import name 'Template' while Using from PIL import Image

标签 python-imaging-library python-3.5 pillow

我目前正在研究图像识别程序 使用: python 3.5 PyCharm Community Edition 2016.3 作为 IDE 我使用 pip install Pillow

安装了 Pillow 3.1.2

我的代码是:

from PIL import Image
im = Image.open('images/dot.png')
im.load()

运行时显示错误

Traceback (most recent call last):
  File "/home/harry/PycharmProjects/python study/image.py", line 1, in <module>
    from PIL import Image
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 31, in <module>
    import logging
  File "/usr/lib/python3.5/logging/__init__.py", line 28, in <module>
    from string import Template
ImportError: cannot import name 'Template'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
    from urllib.request import urlopen
  File "/usr/lib/python3.5/urllib/request.py", line 88, in <module>
    import http.client
  File "/usr/lib/python3.5/http/client.py", line 71, in <module>
    import email.parser
  File "/usr/lib/python3.5/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/usr/lib/python3.5/email/feedparser.py", line 27, in <module>
    from email import message
  File "/usr/lib/python3.5/email/message.py", line 16, in <module>
    from email import utils
  File "/usr/lib/python3.5/email/utils.py", line 40, in <module>
    from email.charset import Charset
  File "/usr/lib/python3.5/email/charset.py", line 15, in <module>
    import email.quoprimime
  File "/usr/lib/python3.5/email/quoprimime.py", line 44, in <module>
    from string import ascii_letters, digits, hexdigits
ImportError: cannot import name 'ascii_letters'

Original exception was:
Traceback (most recent call last):
  File "/home/harry/PycharmProjects/python study/image.py", line 1, in <module>
    from PIL import Image
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 31, in <module>
    import logging
  File "/usr/lib/python3.5/logging/__init__.py", line 28, in <module>
    from string import Template
ImportError: cannot import name 'Template'
*

谁能帮忙解决这个问题

最佳答案

在您当前的工作目录中有一个名为“string.py”的文件。 您不应将该文件命名为与 Python 标准库中的模块或保留字相同的名称。

将文件“string.py”的名称更改为其他名称,然后就可以了

enter image description here

关于python-imaging-library - 显示 ImportError : cannot import name 'Template' while Using from PIL import Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46862245/

相关文章:

python - Django/PIL 错误 - 呈现 : The _imagingft C module is not installed 时捕获异常

python - 将参数传递给自定义异常

python - memory_profiler 的 mprof 未运行

image - PIL : module object has no attribute 'resize'

opencv - 为什么用 cv2 读取图像与 PIL 有不同的行为?

python - 如何在 Windows 中使用 Python BaseHttpRequestHandler 将图像传输到客户端?

python - 如何获取多个字节的最低有效位?

python-如何使用另一列中的值作为 Pandas 中定义的字典的键来更新列?

python - .dilate()OpenCV的替代方法

python - Pillow 调整像素化图像的大小 - Django/Pillow