tensorflow2.0 不适用于带有 python 3.6 的 spyder [英] tensorflow2.0 isn't working with spyder with python 3.6
问题描述
我安装了 anaconda3.5.2,它安装了 python 3.6.10.然后我安装了tensorflow2.0.安装后,从 cmd 控制台进入 python 并将 tensorflow 导入为 tf.我输入了 tf.version,一切看起来都不错.然后我启动 spyder 并执行相同的操作,导入没有给出任何错误,但是 tf.version 表示未定义 tf.我查看了 sys.path,在这两种情况下,路径完全相同.
I had installed anaconda3.5.2 which installs python 3.6.10. I then installed tensorflow2.0. After installation, from cmd console I get into python and import tensorflow as tf. I typed tf.version and all looks good. Then I launch spyder and do the same, the import does not give any errors, however tf.version says tf is not defined. I looked at sys.path and in both cases the paths are exactly the same.
感谢任何帮助和答案.
推荐答案
如果我们在 Base Environment
中安装 Tensorflow
有时会出现这种情况.
This can sometimes be the case if we install Tensorflow
in the Base Environment
.
推荐的方法是在 Anaconda
中创建一个 Virtual Environment
并在该 Virtual Environment
中安装 Tensorflow
,这在大多数情况下都有效.
Recommended way is to create a Virtual Environment
in Anaconda
and install the Tensorflow
in that Virtual Environment
, which works in most of the cases.
使用虚拟环境具有以下优点
Using Virtual Environments has advantages like
- 我们可以在多个
Virtual Environments
中维护多个版本的Tensorflow
,每个Virtual Environment
包含每个version
,例如1.14、1.15、2.0、2.1、2.2等.
- 我们可以在每个
虚拟环境
中使用不同的 - 如果我们想修改任何 Tensorflow API 的
源代码
,我们可以在我们的虚拟环境中进行,而不会影响其在其他虚拟环境
中的功能.
Python Versions
(2.x, 3.6, 3.7
)- We can maintain multiple versions of
Tensorflow
in multipleVirtual Environments
with eachVirtual Environment
comprising eachversion
like1.14, 1.15, 2.0, 2.1, 2.2,etc..
- We can use different
Python Versions
(2.x, 3.6, 3.7
) in eachVirtual Environment
- If we want to modify the
source code
of any of the Tensorflow API, we can do it within our Virtual Environment, without impacting its functionality in otherVirtual Environments
.
在Anaconda
中创建一个新的虚拟环境和安装Tensorflow
的步骤,对于不同的操作系统,如下所示:
Steps for Creating a New Virtual Environment and installing Tensorflow
in Anaconda
, for different Operating Systems, is shown below:
# Create a New Virtual Environment
conda create --name TF_2_VE
# When conda asks you to proceed, type y:
proceed ([y]/n)?
# Activate the Virtual Environment. Conda Version > 4.6
conda activate TF_2_VE
# Activating Virtual Environment, Conda Version < 4.6 and Windows OS
activate TF_2_VE
# Activating Virtual Environment, Conda Version < 4.6 and Linux and Mac OS
source activate TF_2_VE
# Install the TF Version you need
conda install tensorflow
以上命令将安装Tensorflow
的Latest Version
(目前为2.2
).如果你想要像2.0
这样的旧版本,你可以用
The above command will install the Latest Version
of Tensorflow
(2.2
as of now). If you want an older version like 2.0
, you can replace the last step of the above set of commands with
conda 安装 tensorflow==2.0
.
希望这些信息有帮助.快乐学习!
Hope this information helps. Happy Learning!
这篇关于tensorflow2.0 不适用于带有 python 3.6 的 spyder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!