Installing PyTorch via Conda - anaconda

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?

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

I struggled with this and was reminded to RTFM (Read The F'ing Manual) documentation...
See Verify the installation with import torch not pytorch. which is from Pytorch

Related

ModuleNotFoundError: No module named 'dask_geopandas'

i have dask, dask-core and dask geopandas installed as shown:
dask 2021.7.1 pyhd8ed1ab_0 conda-forge
dask-core 2021.7.1 pyhd8ed1ab_0 conda-forge
dask-geopandas 0.1.0a4 pypi_0 pypi
however, when importing I kept getting an error message :
"ModuleNotFoundError: No module named 'dask_geopandas'"
I wonder what has gone wrong with installation, thank you.
This could happen if pip install and conda install installed packages in different paths (this typically happens when the conda environment does not have its own pip).
A simple way out of this is to install everything with conda, so in this case you would run the following within your conda environment:
conda install -c conda-forge dask dask-geopandas
Alternatively, make sure that your conda environment has pip installed also and then run the pip within the conda environment:
conda install -c conda-forge dask pip
# if the conda environment is not activate, then activate it
# using: conda activate the_name_of_your_env
pip install dask-geopandas
In addition, there are specific instructions at https://geopandas.readthedocs.io/en/latest/getting_started/install.html#installing-with-pip about extra steps you may need to take when using pip - you might need a compiler available in your system.

Conda won't remove package

Am I doing something wrong in my commands? I can't remove Keras.
$ conda remove --name myEnv keras
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are missing from the target environment:
- keras
$ conda list --name myEnv keras
# packages in environment at /Users/me/anaconda3/envs/myEnv:
#
# Name Version Build Channel
keras 2.3.1 pypi_0 pypi
The channel pypi for keras means you have mix used pip and conda. To uninstall the keras installed from pypi, use pip.
pip uninstall keras
It's not a good idea to mix use both package managers pip and conda in one environment. If you really need to. Read the official guide Using Pip in a Conda Environment.
conda remove --force (the rest of the command)
Pip Interoperability
As #Simba correctly identified, the package is from PyPI (i.e., it was installed via pip). By default, Conda can recognize the presence of such packages but will not interact with them. However, there is a "preview" configuration option, pip_interop_enabled, that enables such interaction (see Conda v4.6 Release Notes). You could either
Set this option globally:
conda config --set pip_interop_enabled true
conda remove --name myEnv keras
If you have PyPI packages generally, then this should help improve your env stability, but at the cost of slightly longer solve times, since now Conda will account for packages coming from PyPI.
Temporarily turn it on just for this operation
CONDA_PIP_INTEROP_ENABLED=1 conda remove --name myEnv keras

How to make conda recognize pip installed python packages?

I have created a conda environnmennt
and then pip installed tensorflow using a pip wheel. numpy was installed by pip at same stage.
When trying to install scipy,
conda wants to install numpy in parallel of pip installed numpy....?
How to make various installed be recognized by conda ?
This is what the new configuration option pip_interop_enabled, introduced in Conda v4.6 is for. It is still considered a "preview" feature, but I've had success using it:
conda config --set pip_interop_enabled true
Until this feature is released in earnest, I think it would be wise to limit its use to a per-env-basis by using the --env flag when running the above.
It should be kept in mind that preferring Conda packages is still best practice. A must read in this regard is "Using Pip in a Conda Environment".

Pytorch install with anaconda error

I get this error:
C:\Users>conda install pytorch torchvision -c soumith
Fetching package metadata .............
PackageNotFoundError: Package missing in current win-64 channels:
- pytorch
I got conda install pytorch torchvision -c soumith from Pytorch official website and I have OSX/conda/3.6/none for settings on Pytorch site(should be correct). I am new to conda, any tips how to solve this?
Update: From PyTorch 0.4, there is an official Anaconda channel with packages for Windows as well.
You can install the latest pre-built (binary) version of PyTorch (GPU version by default) on windows using:
conda install -c pytorch pytorch
For CPU only version:
conda install -c pytorch pytorch-cpu
For specific version of CUDA say CUDA9.1:
conda install -c pytorch pytorch cuda91
Official instructions for windows are now available here
Old answer for previous versions (<0.4) of PyTorch on Windows:
It looks like you are on windows (win 64) and you are trying to install pytorch by choosing OSX because you don't have an option listed for win64 on pytorch site. (Correct me if that is not the case, I will revise my answer). -c soumith will use soumith's channel which only has packages for Linux and OSX not for windows. That is why you got that error when you ran conda from a windows machine.
You can install pytorch on windows through conda using this command:
conda install -c peterjc123 pytorch
This will fetch the pytorch package using peterjc123's channel which has packages for Win64.
You can install the torchvision package using pip like this:
pip install torchvision
On June,2019, The command generated at pytorch will require dependencies before it can be executed successfully. For example I chose stable pytorch 1.1 build with python 3.6 and Cuda 10.0. The command generated by pytorch page was as follows:
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
But it will not work if you have created a new conda environment like me. The step by step process for setting up pytorch is as follows:
First install the cudatoolkit as follows:
conda install -c anaconda cudatoolkit=10.0
Then install the mkl_fft as follows:
conda install -c anaconda mkl_fft
Assuming you will face no more dependency issues. Use the following command to setup pytorch:
conda install -c pytorch pytorch
This worked for me. But I had setup my new conda environment with scikit-learn and jupyter notebook before starting the pytorch setup. So if any dependency problem arise, it would be a good idea to install both scikit-learn and jupyter notebook as well.
Use the following commands to install pytorch on windows
for Windows 10 and Windows Server 2016, CUDA 8
conda install -c peterjc123 pytorch cuda80
for Windows 10 and Windows Server 2016, CUDA 9
conda install -c peterjc123 pytorch cuda90
for Windows 7/8/8.1 and Windows Server 2008/2012, CUDA 8
conda install -c peterjc123 pytorch_legacy cuda80
I have face similar problem because I have installed pytorch cpu only version. I tried everything and update pytorch to gpu version but nothing helped.
Simple solution is to create new environment and then install pytorch gpu version. It resolve my problem

Pip list shows only one version of `torch`, yet conda list shows two

pip list
conda list
I once install torch 0.1.12, then I remove it, and reinstall it.
How can I remove the 0.1.12 version?
If you install torch 0.1.12 with
conda install pytorch torchvision cuda80 -c soumith,
then just try
conda uninstall pytorch torchvision cuda80 -c soumith.
I tested on my mac and it successfully removed pytorch and all its dependencies, also pytorch 0.1.12 never shows in conda list later.
P.S.: a virtual environment is highly recommended with anaconda.

Resources