出現問題:引用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
