【Python】import thread 导入失败:ModuleNotFoundError: No module named 'thread'
出现问题:引用thread 失败
import thread 导入失败
>>> import thread Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'thread'
pip install thread
C:\Users\xxx>pip install thread Looking in indexes: http://pypi.douban.com/simple ERROR: Could not find a version that satisfies the requirement thread ERROR: No matching distribution found for thread
解决方法:
import _thread
>>> import _thread >>> dir() # 查看已导入模块 ['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_thread']
原因:python3中thread被threading代替,thread被改名为_thread
#兼容python2和python3的写法: import sys #如果版本号是3 if(sys.version[:1] == "3"):import _thread as thread #否则直接引用 else:import thread
-------------------------------------------------------------------------------------
如果万事开头难 那请结局一定圆满 @ Phoenixy
-------------------------------------------------------------------------------------