Python 2.7.5 (default, Sep 12 2013, 12:43:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/urllib.py", line 33, in <module>
from urlparse import urljoin as basejoin
File "/usr/local/lib/python2.7/urlparse.py", line 118, in <module>
from collections import namedtuple
File "/usr/local/lib/python2.7/collections.py", line 9, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name itemgetter
运行import urllib
时会出现此问题。 Python版本是2.7。 Python的版本问题是什么?有人能告诉我如何解决它吗?非常感谢!
答案 0 :(得分:10)
您在当前目录中有一个名为operator.py的文件,因此import operator
正在拾取您的模块而不是Python标准库模块operator
。
您应该将文件重命名为与Python的标准库不冲突。