개발/Python

Installing Ubuntu 24.04 PyTorch (CPU version) using venv

강서버 2025. 11. 15. 07:14
728x90
반응형

(Ex, User home directory : /home/gangserver)

(Ex, Working directory : /home/gangserver/devel/python/torch_cpu)

 

- Run terminal

 

- Create python3 symbolic link python

$ cd /bin

$ ls -al python*

$ sudo ln -s python3 python

$ cd

 

[ Execution log ]

gangserver@RC530-U0922:~$ cd /bin


gangserver@RC530-U0922:/bin$ ls -al python*
lrwxrwxrwx 1 root root      10 11월 12 21:15 python3 -> python3.12
lrwxrwxrwx 1 root root      17 11월 12 21:15 python3-config -> python3.12-config
-rwxr-xr-x 1 root root 8021824  8월 15 02:47 python3.12
lrwxrwxrwx 1 root root      34  8월 15 02:47 python3.12-config -> x86_64-linux-gnu-python3.12-config

 

gangserver@RC530-U0922:/bin$ sudo ln -s python3 python

 

gangserver@RC530-U0922:/bin$ ls -al python*
lrwxrwxrwx 1 root root       7 11월 15 06:55 python -> python3
lrwxrwxrwx 1 root root      10 11월 12 21:15 python3 -> python3.12

lrwxrwxrwx 1 root root      17 11월 12 21:15 python3-config -> python3.12-config
-rwxr-xr-x 1 root root 8021824  8월 15 02:47 python3.12
lrwxrwxrwx 1 root root      34  8월 15 02:47 python3.12-config -> x86_64-linux-gnu-python3.12-config

 

gangserver@RC530-U0922:/bin$ cd
gangserver@RC530-U0922:~$

 

 

- Check Python version

$ python --version

 

[ Execution log ]

gangserver@RC530-U0922:~$ python --version
Python 3.12.3

 

 

- Install Python packages (pip, venv)

$ sudo apt install python3-pip python3-venv

 

[ Execution log ]

gangserver@RC530-U0922:~$ sudo apt install python3-pip python3-venv
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다... 완료
상태 정보를 읽는 중입니다... 완료        
다음의 추가 패키지가 설치될 것입니다 :
  libexpat1-dev libjs-sphinxdoc libpython3-dev libpython3.12-dev python3-dev
  python3-wheel python3.12-dev zlib1g-dev
다음 새 패키지를 설치할 것입니다:
  libexpat1-dev libjs-sphinxdoc libpython3-dev libpython3.12-dev python3-dev
  python3-pip python3-venv python3-wheel python3.12-dev zlib1g-dev
0개 업그레이드, 10개 새로 설치, 0개 제거 및 0개 업그레이드 안 함.
8,770 k바이트 아카이브를 받아야 합니다.
이 작업 후 40.1 M바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n] y
(... Log omitted ...)

 

 

- Create a working directory (Optional - Change to the directory you want to create)

$ mkdir -p ~/devel/python/torch_cpu

 

[ Execution log ]

gangserver@RC530-U0922:~$ mkdir -p ~/devel/python/torch_cpu

gangserver@RC530-U0922:~$

 

 

- Change working directory

$ cd devel/python/torch_cpu

 

[ Execution log ]

gangserver@RC530-U0922:~$ cd devel/python/torch_cpu
gangserver@RC530-U0922:~/devel/python/torch_cpu$

 

 

- Create venv for pytorch cpu version

$ python -m venv .venv

 

[ Execution log ]

gangserver@RC530-U0922:~/devel/python/torch_cpu$ python -m venv .venv

 

 

- Check the venv creation directory

$ ls -al

 

[ Execution log ]

gangserver@RC530-U0922:~/devel/python/torch_cpu$ ls -al
합계 12
drwxrwxr-x 3 gangserver gangserver 4096 11월 15 06:50 .
drwxrwxr-x 4 gangserver gangserver 4096 11월 15 06:25 ..
drwxrwxr-x 6 gangserver gangserver 4096 11월 15 06:24 .venv

 

 

- Activate venv ((.venv) appears before the path)

$ . .venv/bin/activate

 

[ Execution log ]
gangserver@RC530-U0922:~/devel/python/torch_cpu$ . .venv/bin/activate

(.venv) gangserver@RC530-U0922:~/devel/python/torch_cpu$

 

 

- Update pip

$ python -m pip install --upgrade pip

 

[ Execution log ]
(.venv) gangserver@RC530-U0922:~/devel/python/torch_cpu$ python -m pip install --upgrade pip
Requirement already satisfied: pip in ./.venv/lib/python3.12/site-packages (24.0)
Collecting pip
  Using cached pip-25.3-py3-none-any.whl.metadata (4.7 kB)
Using cached pip-25.3-py3-none-any.whl (1.8 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 24.0
    Uninstalling pip-24.0:
      Successfully uninstalled pip-24.0
Successfully installed pip-25.3

 

 

- Installing PyTorch CPU version with pip

$ pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu

 

* Refer to the PyTorch site

------------------------------------------------------------------------------------------------------------------------------------

https://pytorch.org/get-started/locally/

PyTorch Build : Stable (2.9.1)
Your OS : Linux
Package : Pip
Language : Python
Compute Platform : CPU
Run this Command : pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu

------------------------------------------------------------------------------------------------------------------------------------

 

https://download.pytorch.org/whl/cpu

 

download.pytorch.org

 

[ Execution log ]

(.venv) gangserver@RC530-U0922:~/devel/python/torch_cpu$ pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu
Looking in indexes: https://download.pytorch.org/whl/cpu
Collecting torch
  Using cached https://download.pytorch.org/whl/cpu/torch-2.9.1%2Bcpu-cp312-cp312-manylinux_2_28_x86_64.whl.metadata (29 kB)
Collecting torchvision
  Using cached https://download.pytorch.org/whl/cpu/torchvision-0.24.1%2Bcpu-cp312-cp312-manylinux_2_28_x86_64.whl.metadata (5.9 kB)
Collecting filelock (from torch)
  Using cached https://download.pytorch.org/whl/filelock-3.19.1-py3-none-any.whl.metadata (2.1 kB)
Collecting typing-extensions>=4.10.0 (from torch)
  Using cached https://download.pytorch.org/whl/typing_extensions-4.15.0-py3-none-any.whl.metadata (3.3 kB)
Collecting setuptools (from torch)
  Using cached https://download.pytorch.org/whl/setuptools-70.2.0-py3-none-any.whl.metadata (5.8 kB)
Collecting sympy>=1.13.3 (from torch)
  Using cached https://download.pytorch.org/whl/sympy-1.14.0-py3-none-any.whl.metadata (12 kB)
Collecting networkx>=2.5.1 (from torch)
  Using cached https://download.pytorch.org/whl/networkx-3.5-py3-none-any.whl.metadata (6.3 kB)
Collecting jinja2 (from torch)
  Using cached https://download.pytorch.org/whl/jinja2-3.1.6-py3-none-any.whl.metadata (2.9 kB)
Collecting fsspec>=0.8.5 (from torch)
  Using cached https://download.pytorch.org/whl/fsspec-2025.9.0-py3-none-any.whl.metadata (10 kB)
Collecting numpy (from torchvision)
  Using cached https://download.pytorch.org/whl/numpy-2.3.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (62 kB)
Collecting pillow!=8.3.*,>=5.3.0 (from torchvision)
  Using cached https://download.pytorch.org/whl/pillow-11.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.metadata (9.0 kB)
Collecting mpmath<1.4,>=1.1.0 (from sympy>=1.13.3->torch)
  Using cached https://download.pytorch.org/whl/mpmath-1.3.0-py3-none-any.whl (536 kB)
Collecting MarkupSafe>=2.0 (from jinja2->torch)
  Using cached https://download.pytorch.org/whl/MarkupSafe-2.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28 kB)
Using cached https://download.pytorch.org/whl/cpu/torch-2.9.1%2Bcpu-cp312-cp312-manylinux_2_28_x86_64.whl (184.4 MB)
Using cached https://download.pytorch.org/whl/cpu/torchvision-0.24.1%2Bcpu-cp312-cp312-manylinux_2_28_x86_64.whl (1.9 MB)
Using cached https://download.pytorch.org/whl/fsspec-2025.9.0-py3-none-any.whl (199 kB)
Using cached https://download.pytorch.org/whl/networkx-3.5-py3-none-any.whl (2.0 MB)
Using cached https://download.pytorch.org/whl/pillow-11.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.6 MB)
Using cached https://download.pytorch.org/whl/sympy-1.14.0-py3-none-any.whl (6.3 MB)
Using cached https://download.pytorch.org/whl/typing_extensions-4.15.0-py3-none-any.whl (44 kB)
Using cached https://download.pytorch.org/whl/filelock-3.19.1-py3-none-any.whl (15 kB)
Using cached https://download.pytorch.org/whl/jinja2-3.1.6-py3-none-any.whl (134 kB)
Using cached https://download.pytorch.org/whl/numpy-2.3.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (16.6 MB)
Using cached https://download.pytorch.org/whl/setuptools-70.2.0-py3-none-any.whl (930 kB)
Installing collected packages: mpmath, typing-extensions, sympy, setuptools, pillow, numpy, networkx, MarkupSafe, fsspec, filelock, jinja2, torch, torchvision
Successfully installed MarkupSafe-2.1.5 filelock-3.19.1 fsspec-2025.9.0 jinja2-3.1.6 mpmath-1.3.0 networkx-3.5 numpy-2.3.3 pillow-11.3.0 setuptools-70.2.0 sympy-1.14.0 torch-2.9.1+cpu torchvision-0.24.1+cpu typing-extensions-4.15.0

 

 

- Check the installed PyTorch version

$ python

>>> import torch

>>> print(torch.__version__)

 

[ Execution log ]

(.venv) gangserver@RC530-U0922:~/devel/python/torch_cpu$ python
Python 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.9.1+cpu

 

 

728x90
반응형