无法在 PyCharm 2019.2 中导入 Keras(来自 TensorFlow 2.0) [英] Unable to import Keras(from TensorFlow 2.0) in PyCharm 2019.2

查看:17
本文介绍了无法在 PyCharm 2019.2 中导入 Keras(来自 TensorFlow 2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 PyCharm 中安装了稳定版 TensorFlow 2.0(2019 年 10 月 1 日发布).

I have just installed the stable version of TensorFlow 2.0 (released on October 1st 2019) in PyCharm.

问题keras包不可用.

实际错误是:

"无法从 tensorflow 导入名称 'keras'"

我已经通过pip install tensorflow==2.0.0安装了CPU版本,然后通过pip卸载了CPU版本并安装了GPU版本安装tensorflow-gpu==2.0.0.

I have installed via pip install tensorflow==2.0.0 the CPU version, and then uninstalled the CPU version and installed the GPU version , via pip install tensorflow-gpu==2.0.0.

上述工作版本的 TensorFlow 均无法正常工作(无法通过 from tensorflow.package_X import Y 导入 keras 或其他包).

Neither of the above worked versions of TensorFlow were working properly(could not import keras or other packages via from tensorflow.package_X import Y).

如果我将 TensorFlow 恢复到 2.0.0.b1 版keras 可以作为一个包使用(PyCharm 识别它)并且一切运行顺利.

If I revert TensorFlow to version 2.0.0.b1, keras is available as a package (PyCharm recognises it) and everything runs smoothly.

有没有办法解决这个问题?我在安装过程中犯了错误吗?

Is there a way to solve this problem? Am I making a mistake in the installation process?

UPDATE --- 从 Python 控制台导入工作并允许导入没有任何错误.

UPDATE --- Importing from the Python Console works and allows the imports without any error.

推荐答案

对于 PyCharm 用户

对于那些使用 PyCharm 的人.从 此处2019.3 EAP build 193.3793.14>.有了它,您将能够对 TensorFlow 的当前稳定版本(即 2.0)使用自动完成功能.我试过了,它有效:)

For those who use PyCharm. Install future (EAP) release 2019.3 EAP build 193.3793.14 from here. With that, you will be able to use autocomplete for the current stable release of TensorFlow (i.e. 2.0). I have tried it and it works :).

对于其他 IDE

对于其他IDE的用户,这个问题只有在稳定版发布后才会解决,反正现在就是这样.但这可能需要更多时间来修复.请参阅此处的评论.我认为等待并继续使用 version 2.0.0.b1 是明智的.另一方面,如果您不想在将来重构代码,请避免从 tensorflow_core 导入.

For users with other IDEs, this will be resolved only after the stable version is released, which is anyways the case now. But this might take some more time for a fix. See the comment here. I assume it will be wise to wait and keep using version 2.0.0.b1. On the other hand avoid imports from tensorflow_core if you do not want to refactor your code in the future.

注意:要自动完成工作,请使用如下导入语句

Note: for autocomplete to work use import statement as below

import tensorflow.keras as tk

# this does not work for autocomplete 
# from tensorflow import keras as tk  

自动完成功能适用于 CPU 版本的 TensorFlow 2.0.0,但自动完成功能不适用于 GPU 版本.

The autocomplete works for TensorFlow 2.0.0 on CPU version, but the autocomplete does not work for the GPU version.

这篇关于无法在 PyCharm 2019.2 中导入 Keras(来自 TensorFlow 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆