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

查看:2354
本文介绍了无法在PyCharm中导入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软件包不可用.

实际错误是:

"无法从张量流导入名称'keras'"

我已经通过pip install tensorflow==2.0.0CPU version进行了安装,然后通过pip install 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?

更新---从Python控制台导入有效,并且允许导入而没有任何错误.

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

推荐答案

PyCharm用户

对于那些使用PyCharm的人.从此处安装将来的(EAP)版本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中导入Keras(从TensorFlow 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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