记录使用tqdm遇到的错误及解决方法。
问题
如果直接,
import tqdm
import numpy as np
thresholds = np.arange(0.5, 0.55, 0.01)
for threshold in tqdm(thresholds, desc="compute threshold"):
print(threshold)
则会报如下错误,
Traceback (most recent call last):
File "111.py", line 7, in <module>
for threshold in tqdm(thresholds, desc="compute threshold"):
TypeError: 'module' object is not callable
解决方法一
使用tqdm.tqdm(***),
import tqdm
import numpy as np
thresholds = np.arange(0.5, 0.55, 0.01)
for threshold in tqdm.tqdm(thresholds, desc="compute threshold"):
print(threshold)
compute threshold: 0%| | 0/6 [00:00<?, ?it/s]0.5
0.51
0.52
0.53
0.54
0.55
compute threshold: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:00<00:00, 87992.39it/s]
解决方法二
导入tqdm包时,使用 from tqdm import tqdm
from tqdm import tqdm
import numpy as np
thresholds = np.arange(0.5, 0.55, 0.01)
for threshold in tqdm(thresholds, desc="compute threshold"):
print(threshold)
compute threshold: 0%| | 0/6 [00:00<?, ?it/s]0.5
0.51
0.52
0.53
0.54
0.55
compute threshold: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:00<00:00, 89877.94it/s]