Pytorch installation for conda

Over the past few days, I’ve been trying to set up a clean and stable PyTorch environment for my research work. I read online that I the best and most stable thing to do is to install PyTorch with conda installso that it manages any versions of CUDA, NumPy, or other libraries that might clash with what’s already in my environment.

To avoid all of that, I’m hoping to install PyTorch using Conda instead.

I’m still struggling to get the correct commands and channels set up. Previously in the the official guide Pytorch had a conda option for installation which is now gone and only pip3 is available. I’m not entirely sure how to handle this to avoid accidentally mixing pip and conda packages in the same environment.

Thanks in advance — hoping to finally get a stable setup running!

Hello @Victor16 !

Thank you for reaching out here. How are you installing conda? And would you also mind sharing what Platform, Architecture and GPU you are working with?

If you are using miniconda or Anaconda Distribution installers your channel config will automatically be pointed at the Anaconda “defaults” channels. Here is a link for the Anaconda main channel which is part of “defaults”: main

Regardless, the commands below could be used to create a fresh conda environment with and then install the gpu variant of PyTorch.
conda create -n pytorch_env python=3.13 -c defaults
conda activate pytorch_env
conda install pytorch-gpu -c defaults

You can verify the installation with something like this while using the environment.
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else "No GPU")

Happy to chat further if you have any other questions!

Hello Tyler,

Thank you for your response. I’m using the Windows 11 distribution of Anaconda installed from the official website (x86_64). My GPU is a 5060 Ti with Driver Version 591.74 and CUDA Version 13.1. I’m also using VS Code as my IDE.

Unfortunately, this still hasn’t resolved the issue. I followed your instructions (except for using Python 3.12), and the output I received was:

InvalidArchiveError("Error with archive C:\Users\jwb20148\AppData\Local\anaconda3\pkgs\pytorch-2.7.0-gpu_cuda128")

I then switched to the installation command provided on the PyTorch website:

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

With this approach, I successfully installed PyTorch in the virtual environment. I also conda installed matplotlib, scikit‑learn, pandas, and OpenCV( through conda‑forge.)

Unfortunately, my concerns were correct and there is some conflict now. The kernel now crashes whenever I try to import PyTorch. VS Code reports:

Error:

The Kernel crashed while executing code in the current cell or a previous cell.
Please review the code in the cell(s) to identify a possible cause of the failure.
Click here for more info.
View Jupyter log for further details.

Jupyter log here:

16:17:44.748 [error] Disposing session as kernel process died ExitCode: 3, Reason: OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

At this point I’m unsure how to proceed, so any further guidance would be greatly appreciated.

@Victor16 ,
Thanks for this added context. We are currently working to build PyTorch 2.8, 2.9 and 2.10 this quarter. This is a major priority for us currently.
The latest version we have available on the main channel today for Windows CUDA is 2.7. PyTorch 2.7 does not support CUDA >= 13.0 which is likely causing this problem.

Could you try the same command installing from conda-forge? conda-forge is a community driven repository of conda packages. They are currently ahead of us for PyTorch releases. These packages are hosted at conda-forge | Anaconda.org.

conda create -n pytorch_env python=3.12 -c conda-forge
conda activate pytorch_env
conda install pytorch-gpu -c conda-forge

Verifying installation
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else "No GPU")

@Victor16 Some additional info.

The team did some additional investigation. Based on this error:
16:17:44.748 [error] Disposing session as kernel process died ExitCode: 3, Reason: OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

It seems like there is more than one OpenMP implementation installed in your environment.

That pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu130 command is probably what triggered the OpenMP error; the upstream PyTorch wheels likely include their own copies of the Intel OpenMP DLLs, and that’s going to be a problem.

The InvalidArchive error is normally a sign that something messed up in the package download.

I would just suggest deleting the environment (conda remove --all -n <env name>), running conda clean -ay, and then trying to recreate the environment with the commands mentioned above.

Your preinstalled CUDA 13.1 should actually be irrelevant. Conda will install necessary CUDA packages based on your drivers into the conda environment. Anaconda main channel has up to PyTorch 2.7 currently and conda-forge has up to PyTorch 2.10.