Anaconda builds pytorch virtual environment

Anaconda creates a new virtual environment and installs pytorch.

Recently, I started to learn the Pytorch deep learning framework. During the process of installing a certain version of the PyTorch library, all its dependent libraries (such as numpy and other basic scientific computing libraries) will be automatically replaced with the corresponding matching version. Therefore, the automatically replaced basic library is likely to have mismatched conflicts with other advanced libraries, resulting in the failure of the original function, that is, the pollution of the original operating environment. In order to avoid this kind of pollution, it is best to create a new environment, install PyTorch and all the libraries it depends on separately, without interfering with each other, and avoid destroying the original hard-working operating environment.

insert image description here

  1. Open Anaconda's prompt
    insert image description here
  2. create new environment
conda create -n 自己取个名字就好了 python=3.8

Then I named it pytorch

conda create -n pytorch python=3.8

If the following errors occur during the installation process, just restore the default source. Skip here without error

insert image description here
Then I encountered an error, a small scene.

UnavailableInvalidChannel: The channel is not accessible or is invalid.
  channel name: pypi/simple
  channel url: https://mirrors.aliyun.com/pypi/simple
  error code: 404

You will need to adjust your conda configuration to proceed.
Use `conda config --show channels` to view your configuration's current state,
and use `conda config --show-sources` to view config file locations.

The reason for the following is that the mirror source you currently set does not support the package, so you need to reset it

  • Workaround: Restore the default source with the following command
conda config --remove-key channels

-------Error report and solve segmentation---------------------------------------- ------------

Then execute it again

conda create -n pytorch python=3.8

insert image description here
Just enter y,
insert image description here
the new virtual environment is installed successfully
insert image description here
3. Activate the environment

activate pytorch

If not, useconda activate pytorch

exit environment

deactivate pytorch

insert image description here
4. Install Pytorch
and then install Pytorch, enter the official website, select install

https://pytorch.org/

insert image description hereI choose the CPU version
insert image description here
and then run the code in the virtual environment of pytorch:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

After the installation is complete, you can run the program

Enter the python environment, directly enter python, you can

python

You can verify that the installation was successful

import torch 

print(torch.__version__) # pytorch版本
print(torch.cuda.is_available()) # 查看CUDA是否可用
print(torch.cuda.device_count()) # 查看可用的CUDA数量
print(torch.version.cuda) # 查看CUDA版本

Guess you like

Origin blog.csdn.net/qq_45176548/article/details/124729634