程序報錯
Traceback (most recent call last):
File "C:/Users/Northxw/Desktop/Meituan/threademo.py", line 1, in <module>
import threading
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\threading.py", line 7, in <module>
from traceback import format_exc as _format_exc
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 35, in <module>
from token import *
File "C:\Users\Northxw\Desktop\Meituan\token.py", line 7, in <module>
import requests
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 214, in <module>
_lock = threading.RLock()
AttributeError: module 'threading' has no attribute 'RLock'
報錯原因
? 報錯顯示 " AttributeError: module 'threading' has no attribute 'RLock' " ,即 threading 沒有 RLock 屬性,那下面又怎么解釋?
? 可以看到,RLock 是存在的管挟。那又是什么原因呢?經(jīng)過一段時間谷歌,終于找到了類似問題的出錯原因:程序調(diào)用 tokenize.py 時會繼續(xù)調(diào)用 token.py 中的所有代碼犀勒,而本地項目中創(chuàng)建的 token.py 并不是 tokenize.py 想要的 token.py ,所以產(chǎn)生報錯妥曲。
? tokenize.py 的部分源代碼如下:
from builtins import open as _builtin_open
from codecs import lookup, BOM_UTF8
import collections
from io import TextIOWrapper
from itertools import chain
import itertools as _itertools
import re
import sys
from token import *
......
?
解決方案
? 重命名 token.py