Using tensorflow in Spyder-ImportError: Cannot find the specified module


Preface

Because I want to use Anaconda's built-in compiler Spyder, I used Anaconda Prompt to reconfigure tensorflow. I encountered the same error as the cmd that came with Windows. I used the same method to solve the error and successfully tested the hello world program in Anaconda Prompt.
This article introduces how to use tensorflow in Spyder.


One, the problem

An error was reported when using Spyder to compile. This is due to the need to install Spyder in the tensorflow environment.
The test code is as follows:

import tensorflow as tf
hello = tf.constant("hello,tensorflow")
sess = tf.Session()
print(sess.run(hello))

The error screenshot is as follows
Error 1

Two, the solution

Find Anaconda Navigatorand open it in the start menu bar , as shown in the figure. After
turn on
opening, select Environment, then select the environment we created tensorflow, select Not installed, and enter directly in the search box spyder, tick the small box in front, and click Applyto install in the lower right corner , as shown in the figure:
step 1
After the installation is complete, you can Installedview the installed spyder in, green means it has been installed, as shown in the figure:
Step 2
back to the Homeinterface, you can see the installed one Spyder, click Launchrun, as shown in the figure:
Step 3
run in spyder, the first time There will be a
result
lot of warnings in the operation, but ignore it. The output of the second run is normal, as shown in the figure: back to the start menu, you can also see that the Spyder in the tensorlfow environment is generated.
Generate
Note that to use tensorflow, you must open the tensorflow environment spyder, otherwise it will still report an error that the module cannot be found. Open the Spyder below the figure above, and the running result is as shown in the figure.
Still reporting errors
Similarly, using tensorflow in ipython can also use similar steps to install.


to sum up

After successful installation, tensorflow can be used in spyder.

Guess you like

Origin blog.csdn.net/weixin_47585015/article/details/110358026