Compatibility of Python 3.12 with (py)torch,

mcswell: <p>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 <a href="https://answers.launchpad.net/ubuntu/+source/pytorch/+question/821499" rel="noopener nofollow ugc">my thread at a Ubuntu forum</a>, since I initially assumed it was a Ubuntu problem.)  So here are the things I’ve tried, with the results:</p>
<ol>
<li><code>apt install pytorch</code>: “Unable to locate package pytorch”</li>
<li><code>apt install torch</code>: “Unable to locate package torch”</li>
<li><code>apt install python-pytorch</code>: “Unable to locate package python-pytorch”</li>
<li><code>apt install python-torch</code>: “Unable to locate package python-torch”</li>
<li>Variants of the above using pip3, like <code>pip3 install python-pytorch</code>: “error:<br>
externally managed-environment…  try apt install python3-xyz, where xyz is<br>
the package you are trying to install.”</li>
<li>Downloaded <code>torch-2.6.0-cp312-cp312-manylinux1_x86_64.whl</code> and tried<br>
to install it using<br>
pip3: <code>pip3 install --use-wheel --find-links-&lt;path to downloaded whl file&gt;</code><br>
“error: externally managed-environment” again.</li>
<li>I was able to use <code>pipx</code> to install it from the above .<code>whl</code> file, but <code>pipx</code> is for<br>
executables, not libraries, so the files wind up in the wrong place.  Possibly<br>
I could move them to the right place manually, but I have not tried that.</li>
</ol>
<p>If pytorch has been released for Python 3.12, I guess the absence of the pytorch library files when I use <code>apt</code>is an Ubuntu problem.<br>
I used to install library files with <code>pip3</code>, 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…</p>

ptrblck: <p>You need to install PyTorch wheels with a Python package manager instead of <code>apt</code>.<br>
Create a working Python environment in your WSL environment and install the PyTorch wheel via <code>pip install torch</code> for the latest stable version with CUDA support or select a desired version from our <a href="https://pytorch.org/get-started/locally/">install matrix</a>.</p>

mcswell: <p>I guess you’re saying I need to set up a <em>virtual</em> 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.</p>

ptrblck: <p>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 <code>conda</code> might be a good approach as it’s usually easy.</p>

mcswell: <p>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.<br>
Thanks for the help!</p>