How to install TensorFlow on Spyder
1. Preliminary preparation
1.1 Complete the installation of python3.7 and Anaconda, check the official website to install
1.2 Configure environment variables for python3.7 and Anaconda
-
Right click My Computer→Properties→Advanced System Settings→Environment Variables→Find Path in System Variables, and left click→Edit (see the figure below)→Edit text
-
Enter at the end of the text:
C:\Users\YUE123\AppData\Local\Programs\Python\Python37\;C:\Users\YUE123\AppData\Local\Programs\Python\Python37\Scripts;D:\17-install\anaconda install\Scripts;D:\17-install\anaconda install;D:\17-install\anaconda install\Library\bin;
Explanation: Among them, python3.7 has two paths, which need to be determined according to its own software installation path, but the final \Python37\ and \Python37\Scripts are the same; Anaconda has three paths, which also need to be determined according to its own software installation path. , \Scripts and its previous directory and \Library\bin are the same. Note: Use English semicolons to connect the path to the path.
2. Install TensorFlow on Windows
2.1 Enable the command line and install TensorFlow:
- Use the shortcut key Windows+R and enter cmd to enable the command line.
- Enter in the command line:
pip install --user virtualenv
pip install --upgrade tensorflow
- The results are as follows:
2.2 Test whether the installation is successful under Windows
- Enter in the command line:
python
import tensorflow as tf
print(tf.__version__)
- The results are as follows:
3. Configure Tensorflow's virtual environment
- Enter at the command line:
conda remove --name tensorflow --all
- After the operation is complete, enter:
conda create -n tensorflow python=3.7 anaconda
activate tensorflow
conda install spyder
conda install ipython
pip install tensorflow
- After completion, close and open the command line, and enter:
conda activate tensorflow
spyder
- Spyder is now open, enter the test code:
import tensorflow as tf
print(tf.__version__)
- The results are as follows:
hint
- Before opening the program, you need to activate the TensorFlow environment. The specific operation: input on the command line
conda activate tensorflow
, and then inputspyder
, you can start spyder.
- The installed TensorFlow is version 2.0. However, many codes are TensorFlow version 1.0. Running the program of version 1.0 with version 2.0 of TensorFlow will definitely cause errors. There are two ways to solve such problems:
(1) All APIs Update
Open https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0 in Google, which corresponds to two versions of API.
(2) in the program directlyimport tensorflow as tf
toimport tensorflow.compat.v1 as tf
, and add a linetf.disable_v2_behavior()
3. The mounting of TensorFlow version 2.0, may be degraded directly to version 1.0.
Step 1:pip uninstall tensorflow
Step 2:pip install tensorflow==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
Successful installation under Windows!
Next, you need to install Tensorflow in a virtual environment:
Step 1: Click on Anaconda Powershell Prompt and enter pip install tensorflow==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
Step 2: Enter on the command line
conda activate tensorflow
spyder
Step 3: Enter under Spyder
import tensorflow as tf
print(tf.__version__)
The virtual environment is configured successfully!