Install Anaconda3 (with python3.8) and TensorFlow under Windows
1. Download the Anaconda installation package
Anaconda official website installation package download speed is very slow, domestic small partners do not recommend trying.
We can use the Tsinghua University Open Source Software Mirror Site: Tsinghua University Open Source Software Mirror Site , please choose the one that suits your system and download it yourself.
What I chose here is the 86-bit installation package of the Windows system. The installation package
after the download is complete is it.
1. Open the installation package, click Next
2. Click I Agree
3. Just me or All Users, if your computer has several Users, you need to consider this problem. In fact, our computer generally has only one User, and we use it alone. If your computer has multiple users, select All Users, and I will directly
click Next to All User.
4.Destination Folder means "destination folder", you can choose where to install it. The default is to install in the C:\ProgramData\Anaconda3 folder (PS: Everyone knows the C drive). You can also choose Browse… to choose the folder you want to install. The author installs it to F:\Anaconda3 and
continues to click Next
5. The first option is to add environment variables. It is recommended that friends select this option, otherwise it will be troublesome to configure the environment variables by yourself. The second is to use Python 3.8 by default and
6. Then, it starts to be installed automatically (the installation process is still quite slow... It is estimated that it will be better if it is solid)
After the green input bar is full,
or click Next
to cancel these two options directly, and follow Installation has nothing to do with
7. Go to this step, Anaconda has been installed, open it at this time, start -> cmd, type the command in the terminal
The following effect appears, indicating that our installation has been completed, and the Anaconda version is 4.8.3
. Some common operation commands about Anaconda are as follows:
|python -V/–version||View the current environment python version|
|conda -V / –version||View current Anaconda version|
|conda info --sends||View the environment that has been created under Anaconda|
|conda create -n environment name python=version number||Create an environment under the specified python version|
|conda remove -n environment name --all||delete the specified environment|
|conda activate environment name||Activate the current environment and enter|
|conda deactivate||exit the current environment|
|conda install package name||Install the package using Anaconda|
|pip install package name||Install the package (for those packages that cannot be installed through ANaconda or obtained from Anaconda.org, we can usually use the pip command to install the package)|
|conda list||After entering an environment, view all packages (and version numbers) installed in that environment|
|conda update conda||Upgrade the current version of Anaconda|
2. Install tensorflow
TensorFlow has two versions: cpu and gpu. The gpu version requires the support of NVIDIA graphics card and download CUDA and cuDNN. For beginners, we can use the cpu version (here, only the installation of the cpu version is introduced)
1. Open the start menu -> Anaconda3- >Anaconda Prompt, open the Anaconda Prompt console
Anaconda Prompt console interface
2. First select the Tsinghua software repository image to install TensorFlow, so the update will be
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
3. Use Anaconda3 to create a python3.7 environment, the environment name is tensorflow
as of 2020/7/25 TensorFlow only supports Python3.5-3.7 versions under Windows (so when creating this environment, a python3.7 will be downloaded, Sometimes the download will fail, and it will be ok to download it several times), in this case, our python3.8 is only in the base environment, and cannot be used in tensorflow. Friends
can check it from the tensorflow official website by
conda create -n tensorflow python=3.7
Type when Proceed is given
If the download fails unfortunately, type it again (don't worry about creating an environment named tensorflow before the download fails, whether there will be a duplicate name error. The actual processing steps are: check whether there is a tensorflow environment in the environment, if not, create it, yes If the required library is retrieved, the missing library is automatically downloaded, and the library that failed to be downloaded last time will be downloaded again this time)
conda create -n tensorflow python=3.7
After the tensorflow environment is created, type
conda info --sends
It can be found that in addition to the basic environment base, we can also see the environment named tensorflow just created
4. Install the cpu version of TensorFlow
In the previous step, we only created a python environment named tensorflow. In this step, we will use TensorFLow Configure into this environment
to start the tensorflow environment in Anaconda Prompt:
Used to activate the environment we created named tensorflow, configure in this environment,
download and install the cpu version of TensorFlow
pip install --upgrade --ignore-installed tensorflow==2.0
After a long download process (about half an hour here), the cpu version of tensorflow has been downloaded and installed. Explain that the version of tensorflow 2.0 is selected here. As of 2020/7/25, the latest version of tensorflow is 2.2.0, but the most stable one is tensorflow 2.0.0. If you want to try it, you can download the latest version of tensorflow by yourself.
There are no screenshots of the installation completed here, just a download and installation in English, don't look at it. During the download process, if there is no red font and error in the terminal command box, the download is considered complete.
After the above steps, the tensorflow environment has been configured! ! ! ! !
At this point, if we want to exit the tensorflow environment,
You can see that it is back to the basic environment base.
4. The test cpu version of TensorFlow
is the same as section 2.1, open the Anaconda Prompt console (if you did not close Anaconda Prompt in the previous step, then continue to operate)
Let's start tensorflow and enter the python environment
. Notice that when switching to the tensorflow environment, the front of the command line becomes (tensorflow), indicating that we successfully started the tensorflow environment. After entering python, the front becomes >>>, which means that we have Enter the python environment of tensorflow (and the python3.7 environment) and
import tensorflow as tf
You can see that there is no error, the execution is successful, and the installation of this tensorflow cpu version is complete.
Here is an example of an error. If you enter the python compilation environment in the base environment and execute the tensorflow code, it will report an error
that there is no module named "tensorflow". The reason is obvious, that is, we only installed the tensorflow cpu version in the tensorflow environment, and the base There is no tensorflow in the environment
To sum up: I have also installed tensorflow based on Anaconda many times, but every time there will be errors, and most of the sources of errors are the version corresponding problems (PS: The problem of the tensorflow version of the gpu version is more serious, and I posted a classmate's blog about gpu version https://blog.csdn.net/BBJG_001/article/details/95068251 ).
At present, the pro-test available is python 3.7—tensorflow2.0.0