tensorflow2.0 isn't working with spyder with python 3.6

一个人想着一个人 提交于 2021-02-05 07:57:08

问题


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.

Appreciate any help and an answer.


回答1:


This can sometimes be the case if we install Tensorflow in the Base Environment.

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

  • 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.

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

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 install tensorflow==2.0.

Hope this information helps. Happy Learning!



来源:https://stackoverflow.com/questions/60239990/tensorflow2-0-isnt-working-with-spyder-with-python-3-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!