PyTorch projects often need a Python stack that can change without disturbing notebooks, data tools, or the Conda base environment. A named Conda environment keeps the interpreter, pip, and PyTorch packages together for one training or inference workspace.

Conda creates the isolated prefix, and the activated environment's python -m pip command installs the current PyTorch CPU wheels from the official PyTorch wheel index. That split follows current PyTorch packaging guidance while still letting Conda own activation and dependency isolation.

Use the CPU wheel command for local development, tests, or CPU inference. CUDA, ROCm, and conda-forge packages need a separate platform decision, and old -c pytorch Conda commands no longer match current official PyTorch releases.

Steps to create a PyTorch Conda environment:

  1. Open a terminal where Conda activation works.

    If conda activate returns a shell initialization error, initialize Conda for that shell and open a new terminal before continuing.
    Related: How to initialize Conda for a shell

  2. Create a named environment with Python and pip.
    $ conda create --name torch-lab python=3.12 pip --yes
    Channels:
     - conda-forge
    Platform: linux-64
    Collecting package metadata (repodata.json): done
    Solving environment: done
    
    ## Package Plan ##
    
      environment location: /opt/conda/envs/torch-lab
    
      added / updated specs:
        - pip
        - python=3.12
    
    The following NEW packages will be INSTALLED:
    
      pip                conda-forge/noarch::pip-26.1.2-pyh8b19718_0
      python             conda-forge/linux-64::python-3.12.13-hd63d673_0_cpython
    ##### snipped #####
    Preparing transaction: done
    Verifying transaction: done
    Executing transaction: done

    Replace torch-lab with the project environment name. Package versions, builds, and channel names depend on the active Conda distribution.

  3. Confirm that the environment exists.
    $ conda info --envs
    
    # conda environments:
    #
    # * -> active
    # + -> frozen
    base                     /opt/conda
    torch-lab                /opt/conda/envs/torch-lab

    The new environment should appear with its own path under the Conda installation.
    Related: How to list Anaconda environments

  4. Activate the PyTorch environment.
    $ conda activate torch-lab
    (torch-lab) $
  5. Install PyTorch and the common torchvision and torchaudio companion packages.
    (torch-lab) $ python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
    Looking in indexes: https://download.pytorch.org/whl/cpu
    Collecting torch
      Downloading torch-2.12.1+cpu-cp312-cp312-manylinux_2_28_x86_64.whl (192.3 MB)
    Collecting torchvision
      Downloading torchvision-0.27.1+cpu-cp312-cp312-manylinux_2_28_x86_64.whl (1.8 MB)
    Collecting torchaudio
      Downloading torchaudio-2.11.0+cpu-cp312-cp312-manylinux_2_28_x86_64.whl (341 kB)
    ##### snipped #####
    Successfully installed filelock-3.29.0 fsspec-2026.4.0 jinja2-3.1.6 numpy-2.4.4 pillow-12.2.0 torch-2.12.1+cpu torchaudio-2.11.0+cpu torchvision-0.27.1+cpu typing-extensions-4.15.0

    Use the PyTorch install selector for CUDA or ROCm wheels. Keep python -m pip after activation so the package install targets this Conda environment.

  6. Confirm that torch is installed under the environment path.
    (torch-lab) $ python -m pip show torch
    Name: torch
    Version: 2.12.1+cpu
    Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
    Home-page: https://pytorch.org
    License: BSD-3-Clause
    Location: /opt/conda/envs/torch-lab/lib/python3.12/site-packages
    Requires: filelock, fsspec, jinja2, networkx, setuptools, sympy, typing-extensions
    Required-by: torchvision

    The Location value should point inside the named Conda environment, not base or the system Python directory.

  7. Run a PyTorch import and tensor smoke test.
    (torch-lab) $ python -c 'import torch; print(torch.__version__); print(torch.rand(2, 3))'
    2.12.1+cpu
    tensor([[0.2052, 0.7758, 0.2776],
            [0.0726, 0.8090, 0.2486]])