今天在虚拟机中想使用 keras_tuner,结果导入 keras_tuner 之后在 jupyter 中报错:
module ‘google.protobuf.descriptor’ has no attribute '_internal_create_key’
在终端的 python 中也报同样的错误
在百度之后显示是 protobuf 版本过低,于是使用:
pip install --upgrade protobuf
对 protobuf 进行更新,在终端 python 中验证后,发现不报错了
但是回到 jupyter 中还是不停地报相同的错误,让我非常费解,打开 pycharm,也还是报相同的错误。
这说明 jupyter 和终端运行结果不一致,再继续查找资料过后果然发现,终端和 jupyter 的 python 运行路径是不一致的。
# 可以查看当前 python 的运行路径 import sys print(sys.executable)
后来发现我居然有两个 anaconda 的运行环境,运行 conda 下载包指令的时候会 提示 environment inconsistent 运行环境不一致,我删掉了其中一个运行环境,只留下一个,发现之前的问题就都解决了
如果我们在 anaconda 中有多个虚拟环境,一定要注意 jupyter 的 python 运行路径是否正确,以防出现问题。在 pycharm 中有的 anaconda 管理工具,修改起来很方便。



