Anaconda, PyTorch and PyCharm installation tutorials, as well as PyCharm project creation and operation

This article introduces a tutorial on installing the PyTorch deep learning framework based on the combination of the Anaconda environment and PyCharm software.

Table of contents

1. Anaconda installation

(1) Download

(2) Installation

(3) Configure environment variables

(4) Check the installation results

Two, PyTorch installation

(1) Create a virtual environment

(2) Activate virtual environment

(3) Install PyTorch

(4) Install torchvision

 3. PyCharm installation

(1) Download

(2) Installation

(3) Activate the professional version

(4) Create a PyCharm project

(5) Sinicization course

 4. Add the PyTorch environment to PyCharm's interpreter

(1) Import torch running programEdit


1. Anaconda installation

(1) Download

Official website download link: https://www.anaconda.com/Tsinghua
University open source software mirror station: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Select
Anaconda3-2023.03-1-Windows-x86_64. exe (64-bit):

(2) Installation

1. Click next

 2. Click I Agree

3. After selecting All Users, click Next

4. Select the folder where the software is stored (try not to put it on the C drive), and click Next

5. Choose to add anaconda to system variables (check the first box)

(3) Configure environment variables

If the first option is not checked above, you need to manually configure the environment variables.

1. Open Advanced System Settings and click Environment Variables

2. Double-click the Path of the system variable

3. Click New and add the following four paths to the environment variable in turn

(4) Check the installation results

Press the win key + R key to pop up the run box, enter cmd, and the cmd command line window will pop up

1. Verify that the anaconda environment is successfully installed:

conda --version


2. Check which packages anaconda has installed

 Find the anaconda prompt from the start interface and click Start


Enter the following command:

conda list

You can see that common packages such as numpy and sympy have been installed.

Two, PyTorch installation

(1) Create a virtual environment

1. Open the anaconda prompt and enter the following command:

conda create -n pytorch python=3.10

Create a virtual environment named pytorch through conda. 3.9 is the python version. You can change it according to your own needs. Be sure to specify the specific python version.

2. After the creation is successful, enter the following command to view all installed environments:

conda info --envs

(2) Activate virtual environment

Enter the following command:

conda activate pytorch


When the previous change from (base) to (pytorch) means that you have switched to the pytorch virtual environment you created, and then officially entered the installation of pytorch.

(3) Install PyTorch

1. Open the pytorch official website: https://pytorch.org/, click Get Started


2. According to the prompts on the official website, select the appropriate CUDA version and copy the command in the command

3. Open the anaconda prompt command window, enter the pytorch environment just created, and enter the command copied before


What needs to be noted here is that the installation must be run in the virtual environment (pytorch).

(4) Install torchvision

        In the \Anaconda\Scripts> path, open cmd and run the following command.

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple torchvision

 3. PyCharm installation

(1) Download

1. Open pycharm official website: https://www.jetbrains.com/pycharm/download/#section=windows


2. Download the professional version professional

 The amount of data in deep learning is generally large, and the code is usually run on the server, but the professional version of pycharm can be developed remotely. 3. Download the community version community

(2) Installation

1. Click next

2. Select the installation location, try not to choose the C drive

3. Check all the options

 4. Click install

 5. Set environment variables

(3) Activate the professional version

1. As a student or teacher, you can activate it for free. The period of use is one year. It seems that you can apply again when it expires. The application link: link


2. Purchase directly (tb or official)

(4) Create a PyCharm project

 1. Open PyCharm, click【new Project】

  2. new Project

  3. Create

  4. Right click, Run 'main'

(5) Sinicization course

1. Open settings, click 'File', click 'Settings'

2. Click 'Plugins', enter 'chinese', select 'Chinese (Sinplified) Language Pack/Chinese Language Pack', and click 'Install'

 4. Add the PyTorch environment to the PyCharm interpreter

1. Open settings, file -> Settings -> Project:pythonProject

2. Select the python interpreter

3. Click Add Interpreter and select Add Local Interpreter

4. Select the conda environment and select the pytorch.exe interpreter of the pytorch environment

 5. Click OK and wait for the initialization to complete before running the relevant programs:

from __future__ import print_function
import torch
import numpy as np

x = torch.rangd(5, 3)
print(x)

arr = np.ones((3, 3))
print("arr的数据类型为:"+str(arr.dtype))

t = torch.tensor(arr)
print(t)

(1) Import torch running program

Guess you like

Origin blog.csdn.net/u010192735/article/details/131047370