Import urllib or urllib 2 in Python 2.7 failing with ImportError: cannot import name iskeyword

与世无争的帅哥 提交于 2020-01-29 23:17:26

问题


I can't import urllib or urllib2 on my Python 2.6 or Python 2.7 installs.

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] 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/lib/python2.7/urllib.py", line 30, in <module>
    from urlparse import urljoin as basejoin
  File "/usr/lib/python2.7/urlparse.py", line 110, in <module>
    from collections import namedtuple
  File "/usr/lib/python2.7/collections.py", line 10, in <module>
    from keyword import iskeyword as _iskeyword
ImportError: cannot import name iskeyword

I can't seem to find an answer Googling "cannot import name iskeyword" either.


回答1:


There must be some importing conflicts. Do you have any modules named keyword in you workspace? Try next:

>>> import keyword
>>> dir(keyword)


来源:https://stackoverflow.com/questions/6086634/import-urllib-or-urllib-2-in-python-2-7-failing-with-importerror-cannot-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!