Compatibility of Python 3.12 with (py)torch,

I’m trying to install PyTorch on Ubuntu 24 (running in the Windows Subsystem for Linux), under Python 3.12.3, but I can’t get it to work. I posted to thread 110436 “Pytorch for Python 3.12 not available”, and it was suggested I start “a new issue with more details on your environment, how you’re trying to install torch and the error you’re seeing.” (See also my thread at a Ubuntu forum, since I initially assumed it was a Ubuntu problem.) So here are the things I’ve tried, with the results:

  1. apt install pytorch: “Unable to locate package pytorch”
  2. apt install torch: “Unable to locate package torch”
  3. apt install python-pytorch: “Unable to locate package python-pytorch”
  4. apt install python-torch: “Unable to locate package python-torch”
  5. Variants of the above using pip3, like pip3 install python-pytorch: “error:
    externally managed-environment… try apt install python3-xyz, where xyz is
    the package you are trying to install.”
  6. Downloaded torch-2.6.0-cp312-cp312-manylinux1_x86_64.whl and tried
    to install it using
    pip3: pip3 install --use-wheel --find-links-<path to downloaded whl file>
    “error: externally managed-environment” again.
  7. I was able to use pipx to install it from the above .whl file, but pipx is for
    executables, not libraries, so the files wind up in the wrong place. Possibly
    I could move them to the right place manually, but I have not tried that.

If pytorch has been released for Python 3.12, I guess the absence of the pytorch library files when I use aptis an Ubuntu problem.
I used to install library files with pip3, but this appears no longer to be possible, at least under Ubuntu. Am I doing something wrong with pip3 to cause the “externally managed-environment” error? I suppose the solution is to set up a separate Python virtual environment, but that seems a complication…

You need to install PyTorch wheels with a Python package manager instead of apt.
Create a working Python environment in your WSL environment and install the PyTorch wheel via pip install torch for the latest stable version with CUDA support or select a desired version from our install matrix.

I guess you’re saying I need to set up a virtual environment, which will allow me to use pip. Sigh, I really don’t see the point of virtual environments on a machine that only I use, but I guess I’m stuck with it. Thank you for the response.

You don’t need to create virtual environments but would still need to install Python properly at least. If you are stuck, creating virtual environments e.g. via conda might be a good approach as it’s usually easy.

Not sure what “install Python properly” means–it is running (v12.3). In any case, I tried the virtual environment route, and it worked. Looks like I have to install all the other packages I had previously installed, since apparently the venv doesn’t inherit those. But that’s a minor issue.
Thanks for the help!