在学习python的运算符的时候 建立了 operator.py 这个文件 写了一些简单代码
pycharm出现红字如下
Failed to import the site module
Traceback (most recent call last):
File “G:\Anaconda3\lib\site.py”, line 168, in addpackage
exec(line)
File “”, line 1, in
File “G:\Anaconda3\lib\types.py”, line 171, in
import functools as _functools
File “G:\Anaconda3\lib\functools.py”, line 21, in
from collections import namedtuple
File “G:\Anaconda3\lib\collections__init__.py”, line 26, in
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name ‘itemgetter’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “G:\Anaconda3\lib\site.py”, line 541, in
main()
File “G:\Anaconda3\lib\site.py”, line 523, in main
known_paths = addsitepackages(known_paths)
File “G:\Anaconda3\lib\site.py”, line 320, in addsitepackages
addsitedir(sitedir, known_paths)
File “G:\Anaconda3\lib\site.py”, line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File “G:\Anaconda3\lib\site.py”, line 178, in addpackage
import traceback
File “G:\Anaconda3\lib\traceback.py”, line 3, in
import collections
File “G:\Anaconda3\lib\collections__init__.py”, line 26, in
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name ‘itemgetter’
很诡异 不知道为什么 而且同一个文件夹下的其他python文件 运行之后 也会出现这个错误。
后来 惊醒! 可能是文件命名的问题!
然后把 operator 这个文件名字改了 就好啦!