在stackoverflow上查找答案,结果为:
This error can be cause by multiple reasons:
(1) Installing the wrong version of TensorFlow;
You should install TensorFlow >= 1.10 and <=1.15 (don't install TensorFlow 2.0)
(2) When trying to start the server using the command:
bert-serving-start -model_dir cased_L-24_H-1024_A-16/ -num_worker=4
change the path to the model_dir to point to the model directory in your machine.
总结起来就是:
- tensorflow版本需要控制在1.10到1.15之间
bert-serving-start
运行命令中的-model_dir
中的路径时本机模型的绝对路径而非相对路径
按照上述所说进行尝试,发现我自己的机子tensorflow==1.15
这个版本还是不行,最后降低版本至1.14
则不再报标题中的TypeError
错误。
安装指定版本的包:
conda install xxx==1.14.0
xxx对应包名
关键的几个包版本如下:
查看方式:
conda list
最后的tensorflow-gpu
根据个人需求和硬件条件选择性安装。我的机子跑不了GPU版本的,所以最后的运行命令还得调整为以CPU方式运行:
bert-serving-start -model_dir=./chinese_L-12_H-768_A-12/ -num_worker=2 -cpu
运行结果如下:
成功运行!
完结撒花!如有帮助希望点个赞吖~
============ 更新 ============
有网友反映pip install tensorflow==1.14
或pip install tensorflow==1.15
安装不了,我个人认为原因是python版本太高了。
解决方案:
- 创建一个新的虚拟环境并指定python版本:
conda create -n your_env_name python=3.7
- 然后在新创建的虚拟环境中安装上面对应需要的包
本机测试过当python==3.7
时tensorflow==1.14
或1.15
就都能安装了~