In the example below we will install two same Python's versions side by side, but for the different architectures. When to use Conda? When you've been using pre-built Python packages. If you use pip or wheel packages a lot it is better to stick to vanilla Python distribution. That's it.
Make sure you have the following either in ~/.bashrc
or in ~/.bash_profile
files defined
eval "$(/c/tools/miniconda/Scripts/conda shell.posix hook)"
or
source /c/tools/miniconda/etc/profile.d/conda.sh
or
# this will load base profile no matter what settings you have
source /c/tools/miniconda/Scripts/activate
To add Conda hook to Windows command-prompt (this will also enable UTF-8 charset)
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor]
"Autorun"="@chcp 65001>nul & call \"C:\\Tools\\miniconda\\condabin\\conda_hook.bat\""
To add Conda hook to Windows PowerShell
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
$CondaHook = @'
& C:\Tools\miniconda\shell\condabin\conda-hook.ps1
'@
Add-Content -Path $PROFILE -Value $CondaHook
Ad-hoc run Windows PowerShell
powershell.exe -NoExit -ExecutionPolicy Bypass -Command "& C:\Tools\miniconda\shell\condabin\conda-hook.ps1"
To run Conda on Cygwin create new environment variable SHELLOPTS
and set its value to igncr
, then restart your shell.
rundll32.exe sysdm.cpl,EditEnvironmentVariables
-
Base configuration
conda update -n base -c defaults conda conda config --set changeps1 false conda config --set auto_activate_base false # same as export CONDA_AUTO_ACTIVATE_BASE="false" conda config --set auto_update_conda false
-
Create Python 3.6 x86 environment
conda create -n python36_x86 conda activate python36_x86 conda config --env --set subdir win-32 conda install python=3.6 # alternative conda create -n python36_x86 conda install -n python36_x86 -c defaults/win-32 --override-channels python=3.6 # alternative conda create -n python36_x86 -c defaults/win-32 --override-channels python=3.6 # now activate conda activate python36_x86
# alternative conda env create --prefix ./envs -c defaults/win-32 --override-channels python=3.6 conda activate ./envs
-
Create Python 3.6 x64 environment
conda create -n python36_x64 conda activate python36_x64 conda config --env --set subdir win-64 conda install python=3.6 # alternative conda create -n python36_x64 conda install -n python36_x64 -c defaults/win-64 --override-channels python=3.6 # alternative conda create -n python36_x64 -c defaults/win-64 --override-channels python=3.6 # now activate conda activate python36_x64
# alternative conda env create --prefix ./envs -c defaults/win-64 --override-channels python=3.6 conda activate ./envs
-
Manage packages
# list packages conda list -n python36_x64 conda list # search packages conda search requests conda search --channel defaults/win-64 --override-channels requests # install packages conda install --name python36_x64 requests conda install requests conda install -c conda-forge/win-64 --override-channels awscli boto3 # update packages conda update conda conda update anaconda conda update python # remove packages conda remove -n python36_x64 requests conda remove requests
# configure new environments to install packages by default conda config --add create_default_packages awscli # override with --no-default-packages flag conda create -n python36_x64 -c defaults/win-64 --override-channels --no-default-packages python=3.6
-
Update all
conda update --all --yes # except python conda install python=3.6.10
-
Delete environment if not needed
conda env remove -n python36_x86 -y # alternative conda remove -n python36_x86 --all -y
-
Prepared environment definition
# create & delete conda env export -n python36_x64 -c defaults/win-64 --override-channels > environment.yml # same as previous conda env export -n python36_x64 -c defaults/win-64 --override-channels -f environment.yml # now remove conda remove -n python36_x64 --all -y
# restore conda env create -f environment.yml -n python36_x64 -p ./envs
# update conda env update -n python36_x64 --file environment.yml --prune
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html
https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html
https://docs.conda.io/projects/conda/en/latest/configuration.html