Installing PyTorch via Conda

Ron Cohen picture Ron Cohen · Apr 21, 2018 · Viewed 10.1k times · Source

Objective: Create a conda environment with pytorch and torchvision. Anaconda Navigator 1.8.3, python 3.6, MacOS 10.13.4.

What I've tried:

  • In Navigator, created a new environment. Tried to install pytorch and torchvision but could not because the UI search for packages does not find any packages available matching pytorch, torch, torchvision, or similar strings.
  • conda install pytorch torchvision -c pytorch
  • conda update --all

pytorch 0.3.1, torch 0.3.1, and torchvision 0.2.0 now appear as installed in the root environment. However, the root environment is no longer cloneable; the clone button is gray/disabled (it used be enabled/cloneable). I could use the root environment as a fallback but the main point of conda is to be able to create separate and disposable environments. What am I missing?

UPDATE -----------------

Running conda install -c pytorch pytorch yields: # All requested packages already installed. But if I activate the pytorch environment and list the packages therein, there is no package containing the word "torch". If I then do conda search pytorch I get PackagesNotFoundError: The following packages are not available from current channels: - pytorch. If I activate the base environment and then do conda list then pytorch is in the package list for base. So how does one create a separate environment containing pytorch?

Answer

RomualdM picture RomualdM · Oct 16, 2018

You seem to have installed PyTorch in your base environment, you therefore cannot use it from your other "pytorch" env.

Either:

  • directly create a new environment (let's call it pytorch_env) with PyTorch: conda create -n pytorch_env -c pytorch pytorch torchvision

  • switch to the pytorch environment you have already created with: source activate pytorch_env and then install PyTorch in it: conda install -c pytorch pytorch torchvision