Torch is not working with cuda!

Edgar: <p>Hello, I have issue in pycharm: AssertionError: Torch not compiled with CUDA enabled.<br>
I Have CUDA toolkit 12.4.0 installed, torch(2.3.0+cu121) torchvision(0.18.0+cu121) and torchaudio(2.3.0+cu121) are installed and no other version installed. I am using pycharm and I have reinstalled packages there. my OS is Windows 11. I could not find any working solution for days, may be someone here knows what the problem might be. Thanks in advance!</p>

AlphaBetaGamma96: <p>Hi <a class="mention" href="/u/edgar">@Edgar</a>,</p>
<p>If you’re working within the Pycharm IDE, are you sure your IDE has selected the correct environment/interpreter? You might just be using the base environment (which won’t have any packages installed).</p>

Edgar: <p>I’m not quite sure about what environment I’m using but I was installing packages in Pycharm after downloading them through pip</p>

AlphaBetaGamma96: <p>Could you check? If you’re using <code>pip</code> make sure to check what virtual environment you’re using (and also where you installed the packges) and make sure you’ve activated this virtual environment within the PyCharm IDE.</p>

ptrblck: <aside class="quote no-group" data-username="Edgar" data-post="3" data-topic="202581">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/edgar/48/62330_2.png" class="avatar"> Edgar:</div>
<blockquote>
<p>but I was installing packages in Pycharm after downloading them through pip</p>
</blockquote>
</aside>
<p>Could you explain why as it seems you’ve already downloaded the right pip wheels and might have broken the environment by downloading CPU-only binaries in PyCharm?</p>

Edgar: <p>I have checked and everything is alright with the interpreter and environment, also checked cuda availability by package “cuda-available” and got positive results there while torch is still using CPU. I was installing torch with cuda using pip on my laptop but perhaps the problem might be with the added torch in the environment, because it doesn’t show any info about having cuda, for example, there is no “+ cu121”</p>

Edgar: <p>Do you mean that added torch package in Pycharm should also have “+ cu121”? Because I didn’t see any torch with cuda in Pycharm</p>

ptrblck: <p>Yes, assuming you’ve installed another PyTorch pip wheel in Pycharm it should also show the corresponding CUDA runtime version.</p>

Edgar: <p>Pycharm torch has only versions as “number.number.number” without mentioning cuda. The description of torch says “Tensor and Dynamic neural networks in Python with strong GPU acceleration”. Is there a way to find and add the right torch version?</p>

ptrblck: <p>If <code>torch.version.cuda</code> returns <code>None</code> uninstall this CPU-only binary and either keep the previously installed binary with CUDA support or create a new env and install a single binary only with CUDA support.</p>

Edgar: <p>Yes, it returned “None”. I do not have a CUDA torch within a list of packages in Pycharm even though I have it installed on my computer. Or I’m not looking in the right place?<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/6/26324596123a8b3f750d7a7e1b07d8864f09132e.png" data-download-href="https://discuss.pytorch.org/uploads/default/26324596123a8b3f750d7a7e1b07d8864f09132e" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/26324596123a8b3f750d7a7e1b07d8864f09132e_2_544x500.png" alt="image" data-base62-sha1="5rTQKjfuJPJuBiEzizsJl8xDSrQ" width="544" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/26324596123a8b3f750d7a7e1b07d8864f09132e_2_544x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/6/26324596123a8b3f750d7a7e1b07d8864f09132e_2_816x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/6/26324596123a8b3f750d7a7e1b07d8864f09132e.png 2x" data-dominant-color="34373A"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">816×749 49 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>I don’t know which virtual environment is used in Pycharm but you should either make sure the one is used where PyTorch with CUDA runtime is installed or create a new one and install the PyTorch binaries with CUDA support. If you get stuck you might want to post in a Pycharm-specific discussion board, as your current issue is related to the IDE and not PyTorch.</p>