pycharm - 在 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
解决方案
我目前正在使用已安装的 TensorFlow 2 beta 版本,用于为我从 keras 导入的包获取红色曲线(例如,使用from tensorflow.keras import datasets, layers, models
Pycharm 时无法理解数据集、层或模型)。
我发现手动导入keras
包摆脱了错误亮点。转到 Project Interpreter(在 macOS 上为 cmd + ),单击+
按钮,在搜索栏中输入“keras”,选择您需要的版本,然后单击“安装包”按钮。
推荐阅读
- css - 如何使用 print-CSS 拆分长 HTML 表格,以便第一页表格中的拆分为页面底部的 div 留出空间?
- pyinstaller - 在EXE中使用PyInstaller打包数据文件
- c++ - 通过 lambda 部分专门化类模板
- c# - 如何正确反序列化 Json DateTimeOffset?
- ruby - 如何将字符串拆分为 n 个子字符串?
- php - 显示错误:上传路径似乎无效
- c# - 有没有办法禁用所有 WPF 应用程序的缩放,即使 Windows 在每个监视器或系统范围内都有一定的缩放比例?
- cuda - Cuda - nvcc - 没有可在设备上执行的内核映像。问题是什么?
- html - 在 Chrome 中编辑 CSS 规则时不要突出显示 HTML 区域
- mysql - 如何在执行 SQL 转储时替换某些列的值