先说结论:

python库函数和我本地的py文件重名了

今天跑之前一个爬虫程序突然报错:

Traceback (most recent call last):File "F:\pythonProject\main.py", line 1, in import requestsFile "F:\anaconda\lib\site-packages\requests\__init__.py", line 43, in import urllib3File "F:\anaconda\lib\site-packages\urllib3\__init__.py", line 11, in from . import exceptionsFile "F:\anaconda\lib\site-packages\urllib3\exceptions.py", line 3, in from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteReadFile "", line 1007, in _find_and_loadFile "", line 982, in _find_and_load_unlockedFile "", line 925, in _find_specFile "F:\anaconda\lib\site-packages\urllib3\packages\six.py", line 192, in find_specreturn spec_from_loader(fullname, self)File "", line 431, in spec_from_loaderFile "F:\anaconda\lib\site-packages\urllib3\packages\six.py", line 222, in is_packagereturn hasattr(self.__get_module(fullname), "__path__")File "F:\anaconda\lib\site-packages\urllib3\packages\six.py", line 121, in __getattr___module = self._resolve()File "F:\anaconda\lib\site-packages\urllib3\packages\six.py", line 118, in _resolvereturn _import_module(self.mod)File "F:\anaconda\lib\site-packages\urllib3\packages\six.py", line 87, in _import_module__import__(name)File "F:\anaconda\lib\http\client.py", line 71, in import email.parserFile "F:\anaconda\lib\email\parser.py", line 12, in from email.feedparser import FeedParser, BytesFeedParserFile "F:\anaconda\lib\email\feedparser.py", line 27, in from email._policybase import compat32File "F:\anaconda\lib\email\_policybase.py", line 9, in from email.utils import _has_surrogatesFile "F:\anaconda\lib\email\utils.py", line 33, in from email._parseaddr import quoteFile "F:\anaconda\lib\email\_parseaddr.py", line 16, in import time, calendarFile "F:\pythonProject\calendar.py", line 4, in import jieba# 词语切割File "F:\anaconda\lib\site-packages\jieba\__init__.py", line 14, in from . import finalsegFile "F:\anaconda\lib\site-packages\jieba\finalseg\__init__.py", line 6, in from .._compat import *File "F:\anaconda\lib\site-packages\jieba\_compat.py", line 18, in import pkg_resourcesFile "F:\anaconda\lib\site-packages\pkg_resources\__init__.py", line 74, in from pkg_resources.extern import appdirsFile "", line 1007, in _find_and_loadFile "", line 986, in _find_and_load_unlockedFile "", line 666, in _load_unlockedFile "", line 565, in module_from_specFile "F:\anaconda\lib\site-packages\pkg_resources\extern\__init__.py", line 52, in create_modulereturn self.load_module(spec.name)File "F:\anaconda\lib\site-packages\pkg_resources\extern\__init__.py", line 37, in load_module__import__(extant)File "F:\anaconda\lib\site-packages\pkg_resources\_vendor\appdirs.py", line 560, in import win32com.shellFile "F:\anaconda\lib\site-packages\win32com\__init__.py", line 6, in import pythoncomFile "F:\anaconda\lib\site-packages\pythoncom.py", line 2, in import pywintypesFile "F:\anaconda\lib\site-packages\win32\lib\pywintypes.py", line 136, in __import_pywin32_system_module__("pywintypes", globals())File "F:\anaconda\lib\site-packages\win32\lib\pywintypes.py", line 129, in __import_pywin32_system_module__assert sys.modules[modname] is not old_modAssertionErrorProcess finished with exit code 1

观察报错信息有这么一句:

File "F:\anaconda\lib\email\utils.py", line 33, in from email._parseaddr import quoteFile "F:\anaconda\lib\email\_parseaddr.py", line 16, in import time, calendarFile "F:\pythonProject\calendar.py", line 4, in import jieba# 词语切割File "F:\anaconda\lib\site-packages\jieba\__init__.py", line 14, in from . import finalseg

点进去F:\pythonProject\calendar.py文件和F:\anaconda\lib\email\_parseaddr.py 发现

calendar库函数和我本地的文件重名了,将本地的calendar.py改为calendarDemo.py就OK了