首页 > 解决方案 > 在 PyCharm 中使用 tensorflow2.0 时出现“找不到参考”错误

问题描述

当我从 tensorflow 导入包、类或方法时显示以下错误:

Cannot find reference 'keras' in '__init__.py' less... (Ctrl+F1) 
Inspection info: This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.

使用 tensorflow 的预览版时不会发生此问题。但是,程序仍然可以正常运行。我在'tensorflow.keras'中找到包'keras',在编码界面中出现此错误,但是当我更改为导入'tensorflow.python.keras'时它无法运行。我该如何解决这个问题?

我正在使用 tensorflow 2.0.0alpha 和 Pycharm 的最新版本

PyCharm 2018.3.5 (Professional Edition)
Build #PY-183.5912.18, built on February 26, 2019
Licensed to xxx
Subscription is active until May 14, 2019
For educational use only.
JRE: 1.8.0_152-release-1343-b28 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

标签: pycharmtensorflow2.0

解决方案


我目前正在使用已安装的 TensorFlow 2 beta 版本,用于为我从 keras 导入的包获取红色曲线(例如,使用from tensorflow.keras import datasets, layers, modelsPycharm 时无法理解数据集、层或模型)。

我发现手动导入keras包摆脱了错误亮点。转到 Project Interpreter(在 macOS 上为 cmd + ),单击+按钮,在搜索栏中输入“keras”,选择您需要的版本,然后单击“安装包”按钮。


推荐阅读