Deep learning environment configuration 10 - torch==1.7.1 environment configuration under Ubuntu
Many fans reported that TypeError: array () takes 1 positional argument but 2 were given errors, which can be solved by modifying the pillow version.
pip install pillow == 8.2.0
If the following error occurs:
SubProcess ended with return code : 4294967295 .
Copy ptxas to /usr/local/cuda-11.0/ptxas. The download link is:
Extraction code: vyec
I have not made an environment configuration related to Ubuntu , and decided to fill this hole.
The configuration tutorials for each version of pytorch are as follows:
deep learning environment configuration 10 - torch==1.7.1 environment configuration under Ubuntu Deep learning environment configuration 8 - (30 series graphics card) torch==1.7.1 environment configuration depth
Learning environment configuration 5 - torch-cpu=1.2.0 environment configuration
under windows Deep learning environment configuration 2 - torch=1.2.0 environment configuration under windows
1. Anaconda installation
The installation of Anaconda is mainly for the convenience of environment management. You can install multiple environments on one computer at the same time. Different environments place different frameworks: pytorch, tensorflow, and keras can be installed in different environments. You only need to use conda create –n to create a new environment. That's it.
If you have a system with a visual interface, you can directly log in to Anaconda's official website: https://www.anaconda.com/distribution/ . You can directly download the corresponding installation package.
Usually download 64-bit, open after the download is complete.
In addition, you can also download directly in the terminal through the wget command. Specifically as shown.
After the download is complete, the corresponding sh file will appear in the directory. That is, the installation file of anaconda.
First set the sh file to be executable through the instruction.
sudo chmod -R 777 Anaconda3-2022.05-Linux-x86_64.sh
Then use the following command to execute the sh file.
After the implementation, there are a bunch of agreements that need to be followed. Generally, at this time, yes, yes, yes.
There is a long list of protocols in the middle, which will be skipped faster by pressing the space. Then enter yes, otherwise it will not be installed normally.
Then select the installation path. The students can install it according to their own needs. By default, it will be installed in the ~ folder. Enter the address and hit Enter, Anaconda will start installing automatically.
It is recommended to select yes in this step, the conda environment will be automatically initialized, and some tedious steps can be removed.
Open it again and you will have the base environment.
The installation of Anaconda is over.
I am using torch=1.7.1 here, the officially recommended Cuda version is 11.0, so cuda11.0 will be used, and the cudnn corresponding to cuda11.0 is 220.127.116.11.
Network disk download:
Extraction code: ylrh
Official website download:
The address of the cuda11.0 official website is:
cuda11.0 official website address
Then you can download it through the command.
The address of cudnn's official website is:
You need to go in and look for 18.104.22.168.
cudnn official website address
After downloading, get these two files.
Then we open a terminal in this folder and use the following command to start installing CUDA.
sudo sh cuda_11.0.2_450.51.05_linux.run
Because the current Ubuntu system basically automatically installs the graphics card driver, after running, it will generally prompt that the graphics card driver has been installed. At this time, ignore it and directly select Continue to go to the next step. Then accept the next step of the agreement.
Because the graphics card driver has been installed, no longer select Driver in this step, and then select install to install Cuda.
Once installed, CUDA information also needs to be added to ~/.bashrc, so we do that. Open the .bashrc file with gedit or vim.
Then add the following code at the end of the file, and the environment variable has been added at this time.
export PATH = $PATH :/usr/local/cuda/bin export LD_LIBRARY_PATH = $LD_LIBRARY_PATH :/usr/local/cuda/lib64 export LIBRARY_PATH = $LIBRARY_PATH :/usr/local/cuda/lib64
At this point, CUDA has been installed, and Cudnn needs to be further installed.
With the terminal still open, use the following command to extract the Cudnn file. Use unzip for zip files and tar for tgz files.
tar -xvf cudnn-11.0-linux-x64-v22.214.171.124.tgz
After the decompression is complete, you need to copy the files in the cudnn folder to /usr/local/cuda-11.0/lib64/ and /usr/local/cuda-11.0/include/.
Go to the cudnn folder and use the cp command to copy.
cp cuda/lib64/* /usr/local/cuda-11.0/lib64/ cp cuda/include/* /usr/local/cuda-11.0/include/
At this point cudnn is also installed.
ctrl+alt+T, enter the following command in the command prompt:
conda create –n pytorch-gpu python=3.8
conda activate pytorch-gpu
There are two instructions in total:
the previous one is used to create an environment called pytorch-gpu, and the python version of this environment is 3.8.
The latter instruction is used to activate an environment called pytorch-gpu.
Since all our operations must be performed in the corresponding environment, we need to activate the environment before installing the library.
conda activate pytorch-gpu
At this point the terminal looks like:
Then we enter the following command:
# CUDA 11.0 conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch
But if you want to run deep learning models, there are some other dependent libraries that need to be installed. details as follows:
scipy == 1.7 .1 numpy == 1.21 .2 matplotlib == 3.4 .3 opencv_python == 4.5 .3 .56 torch == 1.7 .1 torchvision == 0.8 .2 tqdm == 4.62 .2 Pillow == 8.3 .2 h5py == 2.10.0 _ tensorboard scikit - learn Cython
If you want a more convenient installation, you can create a requirements.txt file on the desktop or elsewhere, and copy the above content into the txt file.
Use the following command to install it. In the following instructions, the path in front of requirements.txt is the path where I put the file on the desktop, and you can modify it according to your computer.
pip install -r ~ / requirements.txt _ _
It should be noted that if the download and installation in pip is slow, you can change the source. You can go to the user folder, create a pip folder, and then create a txt file in the pip folder.
The creation command is as follows. If you are prompted that you do not have permission, add a sudo in front of it:
mkdir ~/pip gedit ~/pip/pip.conf
Modify the content of the file.
[ global ] index - url = https : // mirrors . aliyun . com / pypi / simple [ install ] trusted - host = mirrors . aliyun . com
After all installation is complete, restart the computer.
I personally like VSCODE, so I installed it. Other editing software can also be, personal preference.
Directly load the official website of VSCODE https://code.visualstudio.com/ , click deb to download.
After the download is complete, open the terminal and use the following command to install. Installation is complete and it is ready to run.
sudo dpkg -i code_1.69.2-1658162013_amd64.deb
First click on the plugin module and install python.
After the installation is complete, restart vscode. At this time, the lower left or lower right corner of vscode can be used to select the environment.
After clicking, select the environment. If there is no corresponding interpreter, you can click the refresh in the upper right corner.
Related: Deep learning environment configuration 10 - torch==1.7.1 environment configuration under Ubuntu
- study foreword
- Configuration tutorial for each version of pytorch
- environmental content
- Environment configuration
- 1. Anaconda installation
- Second, the download and installation of Cudnn and CUDA
- 3. Configure the pytorch-gpu environment
- Fourth, install VSCODE