AttributeError: module 'threading' has no attribute 'RLock'

程序报错

Traceback (most recent call last):
  File "C:/Users/Northxw/Desktop/Meituan/threademo.py", line 1, in 
    import threading
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\threading.py", line 7, in 
    from traceback import format_exc as _format_exc
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 5, in 
    import linecache
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 11, in 
    import tokenize
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\tokenize.py", line 35, in 
    from token import *
  File "C:\Users\Northxw\Desktop\Meituan\token.py", line 7, in 
    import requests
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\__init__.py", line 43, in 
    import urllib3
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\__init__.py", line 8, in 
    from .connectionpool import (
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 3, in 
    import logging
  File "C:\Users\Northxw\AppData\Local\Programs\Python\Python36\lib\logging\__init__.py", line 214, in 
    _lock = threading.RLock()
AttributeError: module 'threading' has no attribute 'RLock'

报错原因

  报错显示 " AttributeError: module 'threading' has no attribute 'RLock' " ,即 threading 没有 RLock 属性,那下面又怎么解释?

  可以看到,RLock 是存在的。那又是什么原因呢?经过一段时间谷歌,终于找到了类似问题的出错原因:程序调用 tokenize.py 时会继续调用 token.py 中的所有代码,而本地项目中创建的 token.py 并不是 tokenize.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

参考

  • https://stackoverflow.com/questions/18192967/why-am-i-getting-an-import-error-upon-importing-multiprocessing
  • https://github.com/jupyter/jupyter/issues/249

你可能感兴趣的:(AttributeError: module 'threading' has no attribute 'RLock')