简体   繁体   中英

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

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM