ImportError: cannot import name namedtuple

一曲冷凌霜 提交于 2019-12-19 18:52:26

问题


I have a python script that produces the following error when run:

import urllib2
File "C:\Python27\lib\urllib2.py", line 94, in <module>
import httplib
File "C:\Python27\lib\httplib.py", line 73, in <module>
from urlparse import urlsplit
File "C:\Python27\lib\urlparse.py", line 119, in <module>
from collections import namedtuple
ImportError: cannot import name namedtuple

I also use the openpyxl package, located in C:\Python27\Lib\site-packages, which contains a collections folder with a __init__.py file. I figured this is what causes the problem, because it may be preventing the python 2.7 collections module from being imported.

What can I do to fix this problem?


回答1:


This can also happen if your local script contains a "collections" module due to the way Python handles relative and absolute imports.



来源:https://stackoverflow.com/questions/25025584/importerror-cannot-import-name-namedtuple

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