问题
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