Install the specified cuda, cudnn, pytorch in the anaconda virtual environment of Linux

Comprehension: First of all, the virtual environment of anaconda is really fragrant! Open up a new virtual environment, many environment and version incompatibility problems will no longer exist, especially useful for students who reproduce other people's code.

Conditions: As long as the installed version does not exceed the hardware conditions of your own machine, you can install it.

step:

1. Determine the cuda version installed.

In the virtual environment, first use the conda search cudatoolkit --info command to view all cuda versions in the source and the download address. The red box in the example below indicates the supported cuda version, the corresponding url address and some constraints.

insert image description here

2. Download and install cuda.

Find the cuda version you want and meet your machine conditions, copy the download link corresponding to the url, cd to the download directory you want, and download it with the following code:

wget 复制的 url 链接

Run the following command to install cuda. If it is not in the current directory, an absolute path must be added before the cuda package.

conda install 刚下载的 cuda 安装包

3. Determine the cudnn version corresponding to cuda.

Use the following command to view the version of cudnn supported by conda. It should be noted that the version of cudnn should match the version of cuda. The figure below shows the cudnn version number, url download address and some constraints corresponding to this version.

conda search cudnn --info

insert image description here

4. Download and install cudnn.

Find the cudnn version you want and meet your machine conditions, copy the download link corresponding to the url, and download it with the following code:

wget 复制的 url 链接

Run the following command to install cudnn.

conda install 刚下载的 cudnn 安装包

5. Install pytorch.

After finding the pytorch version supported by the installed cuda version on the official website , copy the command similar to the red box in the figure below to the Linux command line for execution.

insert image description here

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch

5. Test whether the installation was successful.

You cannot use nvcc -V to test whether cuda is successfully installed in a virtual environment. This is because the command returns the default cuda version of the system, not the cuda version used in the current environment. We can use the pytorch command in the python environment to check which cuda is called when executing the python file in the current environment.

# 命令行进入 python 交互环境后执行如下命令
import torch 	# 若不报错则 pytorch 安装成功,否则失败。
torch.__version__	# 查看 torch 版本
torch.version.cuda()	# 若 cuda 安装成功则返回版本号,否则失败。
torch.backends.cudnn.version()	# 若 cudnn 安装成功则返回版本号,否则失败。

insert image description here

Guess you like

Origin blog.csdn.net/qq_42194665/article/details/130028584