编辑器Sublime Text 3,visual studio代码,notepad ++或cmd同样的问题
C:\Users\Egypt>python Desktop/python/any file.py
当我尝试运行任何文件时,我得到了这个
Traceback (most recent call last):
File "Desktop/python/reqweb.py", line 1, in <module>
from selenium import webdriver
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 28, in <module>
import shutil
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 22, in <module>
import bz2
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\bz2.py", line 18, in <module>
from threading import RLock
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\threading.py", line 7, in <module>
from traceback import format_exc as _format_exc
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\tokenize.py", line 34, in <module>
from token import *
File "C:\Users\Egypt\Desktop\python\token.py", line 1, in <module>
import facebook
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\site-packages\facebook\__init__.py", line 30, in <module>
import requests
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
File "C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\logging\__init__.py", line 207, in <module>
_lock = threading.RLock()
AttributeError: module 'threading' has no attribute 'RLock'
请帮助我尝试卸载python并重新安装但同样的问题 此错误仅出现在导入模型内的脚本中
答案 0 :(得分:0)
我意识到上面的评论或多或少地解决了这个问题,但是要解释实际发生的事情(因为我只是遇到了一个非常相似的问题并发现了这个问题):
您的文件C:\Users\Egypt\Desktop\python\token.py
似乎被错误地选为系统from token import *
模块中C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\tokenize.py
语句的来源。它实际上打算引用模块C:\Users\Egypt\AppData\Local\Programs\Python\Python35\lib\token.py
。由于您的文件版本不符合预期,因此引发了异常。
在这种情况下,这些修复中的任何一个都应该起作用: