[Linux] Ubuntu20.04 version configuration pytorch environment 2023.09.05 [Tutorial]

[Linux] Ubuntu20.04 version configuration pytorch environment 2023.09.05 [Tutorial]

1. Install Anaconda virtual environment manager

First, go to the Anaconda official website to download the installation file of the Linux version Anaconda3-2023.07-2-Linux-x86_64.sh, enter the installation file path, and run the following script to install it.

bash Anaconda3-2023.07-2-Linux-x86_64.sh

Installation requires reading the user agreement, just keep pressing enterit. When you reach the current page, you need to output yesfor confirmation to start the installation.

Image

Then follow the prompts to complete the installation.

2. Create a virtual environment and activate it

Anaconda's basic environment management syntax is as follows

  • 创建虚拟环境
conda create -n <your-virtualenv-name> python=3.8
  • 激活虚拟环境
conda activate <your-virtualenv-name>
  • 取消激活虚拟环境
deactivate
  • 移除虚拟环境
conda env remove <your-virtualenv-name>
  • 查看所有虚拟环境
conda env list

After the installation is complete, you can create a virtual environment. After creating the virtual environment, we first activate the environment. For example, I created a virtual environment metaRLand then conda activate metaRLactivated it using

Image

3. Anaconda cancels the default activation of the virtual environment

If we don’t want to activate the anaconda virtual environment every time we start the terminal, we can cancel the default activation, open the terminal and enter the following statement

conda config --set auto_activate_base false

4. Install Pytorch

First go to the Pytorch official website , then select the model of your device and copy the corresponding installation statement to install it.

Image

For example, the installation statement I copied here is

pip3 install torch torchvision torchaudio

Then wait for the installation to complete

Image

after a long wait

Image

Finally, the installation is completed, and a successful installation Suceessfully built litprompt appears.

Image

4. Test pytorch

After the installation is successful, we need to test whether it can be used normally. Open the terminal and start python in the terminal.

python

Import pytorch

import pytorch

View torch version

print(torch.__version__)

Check if cuda is available

print(torch.cuda.is_available())

The following results indicate that the installation is successful.

Image

Reference

https://blog.51cto.com/u_16099166/6739522

おすすめ

転載: blog.csdn.net/qq_44940689/article/details/132684758