Can't install Pytorch on Ubuntu 23.04

I am facing the following error when attempting to install Pytorch on Ubuntu 23.04, I am using Python V 3.11 installed and managed via ASDF VERSION MANAGER

pip list :

Package            Version
------------------ --------
setuptools         68.0.0

the command pip install torch torchvision torchaudio --index-url throw the following error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      Looking in indexes:
      ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
      ERROR: No matching distribution found for setuptools>=40.8.0
      [end of output]

Please help

It’s seems to be an issue with Python 3.11, just changing the version to 3.10.12 make it working properly without issue.

If you are using ASDF VERSION MANAGER then do the following:

$ asdf install python 3.10.12

To to set a specific version of Python for your project, run the following from inside your project folder:

$ asdf local python 3.10.12

Then install Pytorch:

$ pip install torch torchvision torchaudio --index-url

To verify the installation:

$ python

Python 3.10.12 (main, Jul 10 2023, 11:47:06) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.rand(5, 3)
>>> print(x)
tensor([[0.4309, 0.9209, 0.4374],
        [0.4121, 0.4171, 0.0754],
        [0.5129, 0.2636, 0.3915],
        [0.1323, 0.1035, 0.9279],
        [0.6893, 0.3870, 0.8031]])

You can use Python 3.11.4 if you don’t update pip and setuptools. With pip==23.0.1 and setuptools==66.1.1, I installed pytorch 2.0.1(cuda 1.18) successfully.