This article aims to introduce the whole process of configuring a new deep learning environment with conda.
Download Anaconda
Download the Anaconda that matches the python version from the official website , and the Python and Anaconda versions match as follows (the picture comes from this blog ):
In this example, I downloaded Anaconda3-2020.11-Linux-x86_64.sh
Install Anaconda
bash Anaconda3-2020.11-Linux-x86_64.sh
The following interface is displayed
Press Enter until the following interface appears, enter yes
to start the installation, after the installation is complete, the following information is displayed:
Configure the Anaconda environment
vim ~/.bashrc
Enter the vim interface, press i to enter the edit mode, enter
export PATH="/home/anaconda3/bin:$PATH"
After saving and exiting, refresh the configuration environment to check whether the configuration is successful
. ~/.bashrc
conda --version
show as below
conda 4.9.2
The configuration was successful.
query all environments
conda info --envs
Show results:
# conda environments:
#
base * /home/zmq/anaconda3
myenv /home/zmq/anaconda3/envs/myenv
Where * indicates the environment currently in use.
create environment
Create an environment called myenv with python version 3.7
conda create -n myenv python=3.7
Activate the environment
For example, if you want to switch to the myenv environment, enter
conda activate myenv
This command has no output. Then query all environments again:
conda info --envs
Available:
# conda environments:
#
base /home/zmq/anaconda3
myenv * /home/zmq/anaconda3/envs/myenv
It can be found that the asterisk has been transferred to myenv, that is, the currently activated environment is myenv.
Note that using it directly in the centos environment may result in an error:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
At this time, the environment needs to be refreshed, and the following instructions are executed separately
# 激活 anaconda 环境
source activate
# 退出 anaconda 环境
source deactivate
then proceed
conda activate myenv
That's it.
configure cuda
After creating and activating a new environment, in order to install pytorch, we need to configure the appropriate version of cudatoolkit (referred to as cuda) and cudnn.
The first is to check the highest CUDA version supported by the GPU and enter the command
nvidia-smi
Get the following figure:
As shown in the figure, it is version 10.2.
Then open the pytorch official website, and check the currently commonly used versions as follows:
From the official website, we can see that the CUDA version corresponding to the 1.10.2 version of pytorch can be 10.2 and 11.3, so there is still a matching cudnn version. Because the machine I use supports up to version 10.2, CUDA 10.2 is also used as an example here.
Query the version that cudnn matches with cuda
Query directly in the console:
conda search cudnn --info
You can see a lot of the following information:
Find information that matches cuda 10.2:
It can be seen that the version corresponding to cuda 10.2_0 is cudnn 7.6.5. After you get the matching version, you can directly download cuda 10.2 and cudnn 7.6.5 in the new environment .
Install cuda and cudnn
conda install cudatoolkit=10.2
conda install cudnn
Install pytorch
After all installations are successful, enter the command given in the pytorch official website:
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
After the download is complete, enter python to verify whether pytorch is successfully installed:
the reference is successful and no error is reported.
Found conflicts! Looking for incompatible packages.
Creating a new virtual environment to install pytorch will cause Found conflicts! Looking for incompatible packages. This incompatible error. At this time, we can download pytorch adaptively by installing other packages, such as:
conda install -c gpytorch gpytorch
In this way, the problem of wrong version can be avoided.
copy environment
When we run other people's code, we need to configure their environment in setup.py. At this time, create a new conda environment directly, and be careful to match the python version in setup.py
conda -n myenv python=3.8
conda activate myenv
Then enter the same directory as setup.py
cd Name-main
Execute the following commands respectively:
python setup.py build
python setup.py install
Then wait for the installation to complete.