1. Create a virtual environment
conda create -n virtual environment name python=3.6
It prompts me that I have already created this virtual environment, select y. After creation, the following screen is displayed
Check again whether the creation is successful
Enter the following command
conda env list
From the picture below, you can see that it has been created successfully.
2. Activate the virtual environment
Enter the following command to enter the pytoch virtual environment we created
conda activate pytorch
Displaying the above cross-section means that we have entered the virtual environment created
3. Check the appropriate command to download pytorch and download pytorch
Go to the pytorch official website and check the download command corresponding to our computer
PyTorchhttps://pytorch.org/Select the stable version and the system corresponding to the computer, select conda for package (select pip if you have not downloaded anaconda), select python for language, select CPU for compute platform, and copy the command Run in anaconda prompt
The following command is for direct download, which is slower.
conda install pytorch torchvision torchaudio cpuonly -c pytorch
Therefore, we choose mirror download
Enter the following command to download using Tsinghua mirror
conda install pytorch torchvision torchaudio cpuonly -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
A first selection appears during the process, select y
Done appears, which means the download is successful.
4. Verify whether pytorch is installed successfully
Enter the following command to check whether there is torch or pytorch
pip list
It can be seen that the download has been successful
5. Configure pytorch in pychram
(1) Create a new project. Here I built a project1
(2) Selection of python interpreter
Here we can choose a new interpreter or an existing interpreter. Usually we choose an existing interpreter.
That is, click previously configured interpreter, and then click add local interpreter
Select conda, select anaconda\Scripts\conda.exe, and then click on the right to load the environment
Loading the environment,
Then select the pytorch virtual environment we created
The virtual environment of pytorch has been configured, and then Click create, and then configure pytoch in pycharm
(3) Test whether the configuration is successful
Enter the following command to test whether the configuration is successful
import torch print(torch.cuda.is_available())
You can see that the configuration has been successful! ! !
7. Configure pytorch in jupyter
(1) Enter the following command to install the ipykernel package into the conda environment named pytorch so that Jupyter Notebook can be used in this environment
conda install -n pytorch ipykernel
A choice appears, select y
(2) Create a new kernel in the virtual environment
Enter the following command
python -m ipykernel install --user --name pytorch --display-name "pytorch"
The following interface appears, indicating that the creation is successful.
(3) Test whether the configuration is successful
Create a new file and select pytorch
Enter the following command to test
import torch torch.__version__
But an error is reported, check the solutions of other bloggers
The reason for the error may be that the numpy version does not correspond
Enter the following command to uninstall numpy
pip uninstall numpy
Run the test code in jupyter again. At this time The operation was successful, but warning: there is no numpy. We will solve this problem later~~~~~
(4) Install numpy
In the virtual environment we created, install Numpy and enter the following command. The version downloaded here is 1.19.5. Use the mirror download to speed up the download.
pip install -U numpy==1.19.5 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
After the download is successful, the following interface will appear:
(5) Test Numpy
Add a line of code to the file we used to test the torch above, and no error was reported! ! ! Can be used normally
import numpy
The above is installing pytorch and pycharm and jupyter The configuration steps, problems encountered and solutions~~~~~I hope it will be helpful to everyone.