程序报错
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 是存在的。那又是什么原因呢?经过一段时间谷歌,终于找到了类似问题的出错原因:程序调用 tokenize.py 时会继续调用 token.py 中的所有代码,而本地(C:\Users\Northxw\Desktop\Meituan\token.py)的 token.py 并不是它想要的 token.py ,所以产生报错。
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
网友评论