我尝试在安装其库后导入 tkinter,但遇到此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 42, in <module>
import re
File "/home/mohammed/re.py", line 5, in <module>
if re.search('From:', line):
AttributeError: module 're' has no attribute 'search'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/home/mohammed/re.py", line 5, in <module>
if re.search('From:', line):
AttributeError: module 're' has no attribute 'search'
最初的例外是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/tkinter/__init__.py", line 42, in <module>
import re
File "/home/mohammed/re.py", line 5, in <module>
if re.search('From:', line):
AttributeError: module 're' has no attribute 'search'
答案1
您不能拥有一个模块 re 和一个叫 re 的 Python 程序。程序优先于模块。