Anaconda+Tensorflow installation under Win10


Preface

To start deep learning recently, you need to install the tensorflow library and start from scratch on the computer where the system is reinstalled in the laboratory. This article records my installation process and the problems encountered and solutions. Since the blog was written after installation and confirmed that it is feasible, some content is not shown in screenshots.


One, install Anaconda

1. Download

Go to the official website https://www.anaconda.com/distribution/ and
Official website
select the Windows64bit version. The
download
download is successful, as shown in the figure,
software
double-click to run

2. Installation

Install 1
Installation 2
For both options,
Install 3
it is recommended to change the installation path to a drive other than the C drive.
Installation 4
Check the first option to add Anaconda3 to the environment variable;
check the second option to set Python3.8 in Anaconda3 as the default Python. Select tick as needed.
Installation 5
After the installation is complete, click Finish to end the installation.
Since Anaconda does not create shortcuts on the desktop, we need to go to the start bar of the computer to find them: we are using two compilers, Notebook and Spyder. Just drag it to the desktop
Installation 6

3. Inspection

Press Win key + R to search cmd to open the command window, enter the command to view the version status

conda --version

The current version is 4.9.2, and the installation is successful.
Successful installation

Two, environment configuration

1. New environment

In the previous command line window, enter the command to detect the installed environment. If no other environment is created, there is only a default root environment in anaconda.

conda info --envs

surroundings
Enter the following command to create a tensorflow python3.5 environment, the system will automatically choose to allocate a python3.5.x version
(Baidu data shows that tensorflow only supports version 3.5 of python on Windows)

conda create --name tensorflow python=3.5

Then enter the following command to activate the newly created environment

activate tensorflow

The tensorflow in the brackets on the left means that you have entered the newly created virtual environment tensorflow and
Environment 2
enter the following command to check whether the installed Python version is correct.

python --version

The result is shown as version 3.5.6Environment 3

Enter the following command in the command line window to exit the environment, the system will warn and the prompt is changed to conda deactivate

deactivate
改为
conda deactivate

Environment 4
Therefore, use the second command next time you exit, and re-enter the environment to exit again for safety.
Environment 5
The brackets and their contents disappear, indicating that you have exited the virtual environment.

2. Inspection

After exiting the virtual environment, enter the following command to check whether it has been added correctly

conda info --envs

There is one more environment than just before, and the environment configuration is successful.
test

Three, install Tensorflow

1. Installation

Re-enter the tensorflow environment, install tensorflow 2.0.0 in the tensorflow environment, and enter the following command
(this step is due to the higher version, which causes an error later, you can directly install the 1.5.0 version according to the method in the second step of debug)

pip install tensorflow==2.0.0-alpha0

Successful installation

2. Test and debug

Enter the following command in the tensorflow environment to enter python to verify our installed tensorflow

python

Then enter the following code test sentence by sentence

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

But the third sentence of the code is wrong, the error message is as follows

AttributeError: module 'tensorflow' has no attribute 'Session'

Since we are installing tensorflow 2.0.0 version, the corresponding third code statement should be changed as follows

sess = tf.compat.v1.Session()

The third sentence of the code reported an error, but the error was reported when the fourth line of code was entered. The error message is as follows

RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

This time it is still due to the higher version, so install the old version once and for all, and enter the following command to uninstall the current version

pip uninstall tensorflow

Then enter the following command to download the specified version with the domestic mirror source. I downloaded version 1.5.0. You can modify the following numbers according to personal needs.

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.5.0

Test again, the results are shown in the figure
result

to sum up

After installing this tensorflow all night, there were various errors. It was installed correctly at the beginning, but it always showed that the specified module could not be found when importing the module. It also collected a bunch of methods to handle the error, but it may be due to the situation. It is not very consistent (although I think the error is exactly the same), after trying them one by one, there is no result, and finally they can only uninstall all and try new methods. make persistent efforts!

Guess you like

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