Quick Guide: Installing PyTorch in PyCharm under 3 Minutes | Python 3.9 – 3.10

Posted by


PyTorch is a widely used open-source machine learning library for Python and is known for its flexibility and scalability. If you are looking to work with PyTorch in Pycharm, which is a popular Python IDE, you are in the right place. In this tutorial, I will guide you through the process of installing PyTorch in Pycharm in less than 3 minutes.

Before we start, make sure you have Python 3.9 or 3.10 installed on your computer. If not, you can download and install it from the official Python website.

Step 1: Install PyTorch
The first step is to install PyTorch. You can do this using pip by running the following command in your terminal or command prompt:

pip install torch torchvision torchaudio

This command will install the necessary packages for PyTorch, including torchvision and torchaudio. Once the installation is complete, you can move on to the next step.

Step 2: Open Pycharm
Open Pycharm on your computer. If you don’t have Pycharm installed, you can download it from the JetBrains website and follow the installation instructions.

Step 3: Create a New Project
Create a new project in Pycharm by clicking on "Create New Project" or going to File > New Project. Give your project a name and select the location where you want to save it. Click on "Create" to create the project.

Step 4: Set up a Virtual Environment
Setting up a virtual environment is important to isolate your project dependencies from other projects. To set up a virtual environment in Pycharm, go to File > Settings > Project: your_project_name > Python Interpreter. Click on the gear icon and select "Add…".

Choose "Virtualenv Environment" and select the Python interpreter you want to use (Python 3.9 or 3.10). Click on "OK" to create the virtual environment.

Step 5: Install PyTorch in Pycharm
To install PyTorch in Pycharm, go to File > Settings > Project: your_project_name > Python Interpreter. Click on the "+" icon to add a new package. In the search bar, type "torch" and click on the package you want to install. Click on "Install Package" to install PyTorch.

Step 6: Verify the Installation
To verify that PyTorch is successfully installed, open a new Python file in Pycharm and type the following code:

import torch
print(torch.__version__)

Run the code by clicking on the "Run" button or pressing Shift + F10. If the installation was successful, you should see the version of PyTorch printed in the console.

Congratulations! You have successfully installed PyTorch in Pycharm in less than 3 minutes. You can now start building machine learning models using PyTorch in Pycharm.

0 0 votes
Article Rating
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@honkhonkv2236
1 month ago

Thanks !

@NomadicBrian
1 month ago

Excellent. At first 'import torch' was not recognized even through I saw 'torch' in the setup like you showed us. I used the suggestion to 'install package' and heard my machine buzz..buzz and 'torch' was recognized. I used PyCharm 2023.3.5. Printed the version 2.2.2+cpu. OK. Thanks sir.

@bongmastii
1 month ago

nice video, unfortunately I got this error:
Traceback (most recent call last):
File "/Users/jamil/PycharmProjects/pytorchProject/main.py", line 1, in <module>
import torch
ModuleNotFoundError: No module named 'torch'

@user-wu2qw2nh4m
1 month ago

I'm not able to install pytorch.pls could you help me

@TheVideoVolcano
1 month ago

Does it have to by 3.9? pip cannot find module 'torch'.
*Edit: I was right

@MO-vo7rz
1 month ago

Thanks