gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:23:14 28 4
gpt4 key购买 nike

我目前正在研究图像识别程序使用: python 3.5PyCharm 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com