How to build a Pytorch environment on Ubuntu

This article was written to remember to build an environment for ** pytorch ** with ** ubuntu **. If you want to know about pytorch, please see the article here.


  • ubuntu18.04
  • GeForce GTX TITAN X
  • CUDA 10.0
  • anaconda 4.8.3
  • python 3.7
  • pycharm

If you want to know GPU related information (CUDA etc.), please refer to the article here.


Now let's build the environment.

1. 1. pycharm installation

This time the IDE uses pycharm.

Method 1 Obtain the download file from the site

The installation destination is the following URL.

You can download the following Communities. (Students can also use Professional if they have the email address specified by the school.) Screenshot from 2020-11-10 20-57-56.png For the setup, I referred to the here site.

Method 2 Download from ubuntu software

You can download it from the ubuntu launcher or from the ubuntu software in Application Search. Screenshot from 2020-11-10 21-04-09.png Please refer to the above Site for setup.

2. 2. anaconda installation

The installation destination is the following URL. Screenshot from 2020-11-10 21-18-31.png The latest version will be installed when you download from the above URL. If you want an older version, you can choose from here.


First, move to the folder where you downloaded anaconda on your device. Therefore,

$ bash

The file name is the file name you dropped.

Please, press ENTER to continue

When the command appears, press enter. Then scroll down the description

Do you accept the license terms?[yes|no]

When the command appears, type yes and press enter. Next, you will be asked about the pass, but if you do not change it, you can enter as it is. You will be asked if you want to enter VS Code, but this time I will set it to no.

It is OK if you do not throw an error by typing the following command at the end.

$ conda -V
If you throw an error

Open the anaconda config file in the vim editor

$ vi ~/.bashrc

Add the following path as it can be anywhere. Insert command: i Save command: ZZ

$ export PATH=~/anaconda3/bin:$PATH

Execute the following command after adding

$ source ~/.bashrc

If you execute the following command again, the version of anaconda will come out.

$ conda -V

If you have any concerns about the path, please refer to here.

Create a virtual environment with anaconda

This time I want to install pytorch on the virtual environment of anaconda, so first create the virtual environment of anaconda. Here, specify what you want to use for python.

$ conda create -n test_torch python=3.7 anaconda

Check if the virtual environment is created.

$ conda info -e
# conda environments:
test_torch                       /home/user/anaconda3/envs/test_torch

Make the virtual environment Active.

$ conda activate test_torch

When you check the state of the virtual environment

$ conda info -e
# conda environments:
test_torch                    *  /home/user/anaconda3/envs/test_torch

You can see that the virtual environment has been successfully started. By the way, if you want to make the virtual environment inactive, use the following command.

$ conda deactivate

Set up pytorch

Install pytorch on the virtual environment. Since pytorch will be used on GPU this time, install the GPU version with the command below cuda. It is safe to put a cuda toolkit that is compatible with cuda in your computer. Check the supported cuda and commands from here.

$ conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

Next, create an environment for pytorch with pycharm. Please refer to the here site for the detailed procedure. I will briefly introduce it here. In pycharm's new project, click "..." in the Visiting interpreter.       pycharm After that, specify the python of the virtual environment created earlier from the "..." of the interpreter of Conda Environment.       pycharm Finally, press Create to create the environment.

As a test, after creating a python file from new, execute the following code

import torch

num = torch.randn(3,3)


If you get such a result, you are successful. Thank you for your hard work.

tensor([[-1.3524, -0.1332, -1.7219],
        [ 1.1739,  0.3055,  1.4518],
        [-2.2588, -1.2884, -1.4783]])


I'm in the process of switching from Keras to Pytorch, but I feel that Pytorch will become the mainstream from now on, so I want to learn it as soon as possible.


Someone please teach me the code to center the image on qiita ...

Recommended Posts

How to build a Pytorch environment on Ubuntu
Build a XAMPP environment on Ubuntu
How to build vim on Ubuntu 20.04
How to build a Ruby on Rails environment using Docker (for Docker beginners)
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Memo to build a Servlet environment on AWS EC2
How to use Bio-Formats on Ubuntu 20.04
How to install WildFly on Ubuntu 18.04
How to install GNOME as a desktop environment on CentOS 7
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
[Ruby] Building a Ruby development environment on Ubuntu
Build a Java development environment on Mac
How to change the timezone on Ubuntu
Build a JMeter environment on your Mac
How to build Rails 6 environment with Docker
A story of frustration trying to create a penetration environment on Ubuntu 20.04
How to install the language used in Ubuntu and how to build the environment
Steps to build a Ruby on Rails development environment with Vagrant
Try to build Java8 environment on Amazon Linux2
How to deploy a container on AWS Lambda
How to configure ubuntu to be used on GCP
Write a dockerfile to start jupyter-lab on ubuntu
How to install network drivers on standalone Ubuntu
[Java] Build Java development environment on Ubuntu & check execution
Minimal steps to set up a Ruby environment with rbenv on Ubuntu 20.04
How to install NVIDIA driver on Ubuntu 18.04 (Note)
Build a Laravel environment on an AWS instance
How to install multiple JDKs on Ubuntu 18.04 LTS
How to build android-midi-lib
[Rails] How to build an environment with Docker
Build a Java runtime environment on Sakura VPS
Build Zabbix on Ubuntu 20.04
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
Build a development environment to create Ruby on Jets + React apps with Docker
Build Ubuntu 20.04 LTS desktop environment on Raspberry Pi 4 (+ Japanese)
How to create a Java environment in just 3 seconds
Build a Ruby on Rails development environment on AWS Cloud9
How to build docker environment with Gradle for intelliJ
How to install NVIDIA driver on Ubuntu ssh destination
[Java] How to execute tasks on a regular basis
How to build Java development environment with VS Code
Try to build a Java development environment using Docker
Build VNC Server on Ubuntu 20.04
How to deploy on heroku
How to leave a comment
Ubuntu on Windows build speed
Ruby ① Build a Windows environment
How to insert a video
How to add HDD to Ubuntu
How to create a method
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
How to deploy a simple Java Servlet app on Heroku
How to get inside a container running on AWS Fargate
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Express ~
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
How to Burning a Install Disk of Windows from Ubuntu
How to deploy a kotlin (java) app on AWS fargate