[英]tensorflow2.0 isn't working with spyder with python 3.6
I had installed anaconda3.5.2 which installs python 3.6.10.我已经安装了安装 python 3.6.10 的 anaconda3.5.2。 I then installed tensorflow2.0.
然后我安装了tensorflow2.0。 After installation, from cmd console I get into python and import tensorflow as tf.
安装后,从 cmd 控制台进入 python 并将 tensorflow 导入为 tf. I typed tf.
我输入了 tf. version and all looks good.
版本,一切看起来都不错。 Then I launch spyder and do the same, the import does not give any errors, however tf.
然后我启动 spyder 并执行相同的操作,导入没有给出任何错误,但是 tf. version says tf is not defined.
版本说 tf 未定义。 I looked at sys.path and in both cases the paths are exactly the same.
我查看了 sys.path,在这两种情况下,路径完全相同。
Appreciate any help and an answer.感谢任何帮助和答案。
This can sometimes be the case if we install Tensorflow
in the Base Environment
.如果我们在
Base 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.推荐的方法是在
Anaconda
创建一个Virtual Environment
并在该Virtual Environment
安装Tensorflow
,这在大多数情况下都有效。
Using Virtual Environments has advantages like使用虚拟环境具有以下优点
Tensorflow
in multiple Virtual Environments
with each Virtual Environment
comprising each version
like 1.14, 1.15, 2.0, 2.1, 2.2,etc..
Virtual Environments
维护多个版本的Tensorflow
,每个Virtual Environment
包含每个version
如Tensorflow
1.14, 1.15, 2.0, 2.1, 2.2,etc..
Python Versions
( 2.x, 3.6, 3.7
) in each Virtual Environment
Virtual Environment
使用不同的Python Versions
( 2.x, 3.6, 3.7
)source code
of any of the Tensorflow API, we can do it within our Virtual Environment, without impacting its functionality in other Virtual Environments
.source code
,我们可以在我们的虚拟环境中进行,而不会影响其在其他Virtual Environments
功能。 Steps for Creating a New Virtual Environment and installing Tensorflow
in Anaconda
, for different Operating Systems, is shown below:在
Anaconda
创建新的虚拟环境和安装Tensorflow
步骤,对于不同的操作系统,如下所示:
# 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
The above command will install the Latest Version
of Tensorflow
( 2.2
as of now).上述命令将安装
Latest Version
的Tensorflow
(截至目前为2.2
)。 If you want an older version like 2.0
, you can replace the last step of the above set of commands with如果你想要像
2.0
这样的旧版本,你可以用上面的命令集的最后一步替换
conda install tensorflow==2.0
. conda install tensorflow==2.0
。
Hope this information helps.希望这些信息有帮助。 Happy Learning!
快乐学习!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.