tensorflow2.0 不适用于带有 python 3.6 的 spyder [英] tensorflow2.0 isn't working with spyder with python 3.6

查看:50
本文介绍了tensorflow2.0 不适用于带有 python 3.6 的 spyder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 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等.
  • 我们可以在每个虚拟环境
  • 中使用不同的Python Versions(2.x, 3.6, 3.7)
  • 如果我们想修改任何 Tensorflow API 的源代码,我们可以在我们的虚拟环境中进行,而不会影响其在其他虚拟环境中的功能.
  • We can maintain multiple versions of Tensorflow in multiple Virtual Environments with each Virtual Environment comprising each version like 1.14, 1.15, 2.0, 2.1, 2.2,etc..
  • We can use different Python Versions (2.x, 3.6, 3.7) in each Virtual 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 other Virtual 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

以上命令将安装TensorflowLatest 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屋!

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