Install tensorflow (cpu version) on win10
If you have any questions, please correct me, if there is any infringement, please delete the text in private chat
Article directory
-
- 1. Environment required before installation
- 2. Install tensorflow environment
-
-
- 1. Create and install tensorflow environment
- 2. Test whether tensorflow is installed successfully
- Supplementary content
- References
-
1. Environment required before installation
Before installing tensorflow, you need to install the anaconda and pycharm environment first. If you have already installed it, you can directly jump to the Install tensorflow environment section. The installation process is as follows:
- anaconda
1) Download the installation package. When downloading anaconda, you can directly search and download it in the software store that comes with the computer; if you have special requirements for the anaconda version, it is recommended to download it from the anaconda official website.
2) Install. Double-click the downloaded installation package. It is not recommended to set the installation path to C drive. This article sets the installation path toD:\anaconda
, you can choose the installation path according to your own storage space, and the rest are default options.
3) Set environment variables. After the installation is complete, add “Library\bin” and “Scripts” in the installation directory to the system “PATH” environment variable, as shown in the figure:
- pycharm download and installation
Second, install the tensorflow environment
1. Create and install tensorflow environment
-
Start the anaconda prompt. Click to start the anaconda command line, as shown below:
-
Restore the download source to the default source. Since the Tsinghua University Open Source Software Mirror Station has suspended the Anaconda mirror service, you need to use the following command to restore the download source to the default source:
conda config --remove- key channels
If the following error occurs after using the command, it means that the download source is already the default source, just continue with the next steps:
-
Update conda to the latest version. Use the following command to update:
conda update -n base conda
-
Create tensorflow-cpu virtual environment. tensorflow-cpu is the name of the environment, which can be changed by yourself. The creation command is as follows:
conda create -n tensorflow-cpu # conda create -n name
-
Log in to the tensorflow-cpu environment. Use the following command to log in to the created environment. The content in the first brackets is the name of the current environment:
conda activate tensorflow-cpu # conda activate name
The actual location of the newly created virtual environment is in anaconda Under the installation location/envs directory. As shown in the picture:
-
Install tensorflow and its dependent environment. Enter the following command to install, try the command twice before giving up if unsuccessful:
conda install tensorflow
-
Set pycharm to run IDE for tensorflow. Take a look at the setting up pycharm section of this great tutorial.
2. Test whether tensorflow is installed successfully
-
Create a python file on pycharm and run the following code:
import tensorflow as tf if __name__ == '__main__': tf.compat.v1.disable_eager_execution() hello = tf. constant('hello, tensorflow') sess = tf.compat.v1.Session() print(sess. run(hello))
-
If the operation is successful, the installation is successful. The picture of the successful operation is as follows:
Supplementary content
- Supplement, the command to exit the environment is, for example, exit to the base environment in the tensorflow-cpu environment:
conda deactivate
References
- How to install tensorflow (cpu version) on win10
- Pycharm community version download and installation tutorial
- anaconda latest version_Conda|Python package and version management tool
- Anaconda creates a virtual environment and reports an error—UnavailableInvalidChannel: The channel is not accessible or is invalid