问题描述

最近新尝试了 TensorFlow 2.0,在 PyCharm 中运行的时候,发现 tf.keras 背景是黄色的,提示 cannot find reference 'keras' in '__init__.py',虽然代码还能运行,但是对于强迫症来说简直不能忍。(对了,有关 keras 的自动补全、参数提示这类也不会显示)

环境

  • Windows 10
  • PyCharm Community 2019.1
  • Python 3.7
  • TensorFlow 2.0.0-alpha0

解决方案

既然 PyCharm 找不到引用,那我们换个地方引:

from tensorflow.python import keras

这样就舒服多了。

Reference

Jimmyguding. (March 12, 2019). PyCharm cannot import tensorflow.keras. Retrieved from https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002486739-PyCharm-cannot-import-tensorflow-keras?page=1#community_comment_360000407199

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐