BUG
最近复用以前的错误代码,结果发现了一个bug,bug如下:
File "/home/michael/work/oanda/src/oanda/trend_prediction/find_optimal_model.py", line 124, in <module>
main()
File "/home/michael/work/oanda/src/oanda/trend_prediction/find_optimal_model.py", line 116, in main
trials=trials)
File "/home/michael/work/oanda/runtime/lib/python3.5/site-packages/hyperopt/fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "/home/michael/work/oanda/runtime/lib/python3.5/site-packages/hyperopt/base.py", line 635, in fmin
return_argmin=return_argmin)
File "/home/michael/work/oanda/runtime/lib/python3.5/site-packages/hyperopt/fmin.py", line 314, in fmin
pass_expr_memo_ctrl=pass_expr_memo_ctrl)
File "/home/michael/work/oanda/runtime/lib/python3.5/site-packages/hyperopt/base.py", line 786, in __init__
pyll.toposort(self.expr)
File "/home/michael/work/oanda/runtime/lib/python3.5/site-packages/hyperopt/pyll/base.py", line 715, in toposort
assert order[-1] == expr
TypeError: 'generator' object is not subscriptable
原因与解决方案
思考考虑到之前我更新了类库,所以最先考虑的是类库问题,但是是在找不到是那个类库的问题,查了Hyperopt源码也没什么用.大概僵持了二十分钟,决定还是去Github查查issues.确实找到了解决方案.
原因与解决底层库networkx更新造成的,Hyperopt不支持networkx-2.0,我换成了1.11版本就OK了.
pip install networkx==1.11
blog,没百度到这个错误,所以写了博客,如文章题目使用关键词Hyperopt+TypeError: 'generator' object is not subscriptable
可以找到,算是造福一下小白.