Open-source, cross-platform, package and environment management, for any language
- Quick Start
- Installing Conda
- Configuring Conda
- Using Conda
- Create and switch between conda environments
- Install, upgrade, and remove conda packages
- Document, share, and recreate conda environments
- Uninstalling Conda
-
Download MiniConda installer
http://conda.pydata.org/miniconda.html
-
Install MiniConda under user home (no admin, no sudo):
http://conda.pydata.org/docs/install/quick.html
-
Create config file
$HOME/.condarc
for local channel:allow_other_channels : false channels: - http://hostname/conda/pkgs/free
-
Create a conda env:
$ conda create -n py34 python=3.4.1 \ ipython=5 numpy=1.10 scipy matplotlib h5py pandas
-
Activate conda env:
$ source activate py34 # Windows: "activate py34"
-
Run code to test:
$ python -c \ "import numpy as np; print(np.__version__)"
-
Easiest way to install conda is via MiniConda:
-
Download MiniConda Installer with browser
-
You can create and use both py2 and/or py3 envs with "MiniConda for Python 3"
-
Check MD5 hash for the downloaded installer file.
-
Launch MiniConda Installer (bash script with embedded binaries)
-
Chose install path, default user home, e.g.
/home/juser/
# Linux/OSX (Win: replace "which" with "where")
$ which conda
$ which python
$ echo $PATH
List packages in default conda environment: should be ~ 10, including conda, python, setup tools, wheel (pip), zlib, etc.
$ conda list
-
Test access to conda package repository at Continuum: http://repo.continuum.io
-
Other conda repos can be found at https://anaconda.org, e.g. conda-forge
- Inside your company, test access to the internal package mirror
- use browser to view this URL: http://hostname/conda/pkgs/free
You should see the following directories in the browser:
linux-64/
osx-64/
win-64/
noarch/
Each will contain a long list of conda package files.tar.bz2
.
If you can see those, test conda search
on that mirror:
$ conda search python --override-channels -c http://hostname/conda/pkgs/free
You should get several listings, including 2.7, 3.4, 3.5, 3.6 and any pkg with the string "python" in the name.
A conda "channel" is just file location (URL) where a conda package file repository is located.
To set up an internal channel, you need to:
- Create a specific dir tree containing packages (
http://hostname/conda/pkgs/free
) - Build or copy a package index into the top of that dir tree (
repo.data.json
) - Create a conda user config file pointing to dir tree (
.condarc
)
Create a .condarc
file for your user in your home dir:
/home/juser/.condarc
Edit the .condarc
file such that it contains only:
allow_other_channels : false
channels:
- http://hostname/conda/pkgs/free
With your config in place, the following cmd will list python versions available from the pkg repo:
$ conda search python
List conda environments, NOT their packages:
$ conda env list
See a list of packages in the default "root" env:
$ conda list
See a list of packages in a named env:
$ conda list -n py34
Here we show how to create three different environments:
$ conda create -n py27 python=2.7
$ conda create -n austin python=3.4
$ conda create -n texas python=3.6
Notice that the environment name can be anything, e.g. texas
-
By default, every new shell you open uses what conda calls it's
root
environment. -
This has nothing to do with "system root" or "root user".
-
To use other environments you have created, you must
activate
them. -
To verify, test the path to python after switching.
# Linux/OSX $ source activate py27 $ which python
...for Windows, drop word "source", use "where" not "which"
-
activate
also used for switching between envs:# Linux/OSX $ source activate py34 $ which python
-
Use
deactivate
to "switch" to the "root" conda env:# Linux/OSX $ source deactivate $ which python
...for Windows, drop word "source", use "where" not "which"
-
How do you "switch" back to the system python?
-
Easiest way is a shell config
-
Define shell functions in your
~/.bashrc
:export ORIGINAL_PATH=$PATH use_conda(){ CONDA_PATH="~/anaconda/bin" export PATH="$CONDA_PATH:$ORIGINAL_PATH" echo "Added conda to your PATH" python --version } use_original(){ export PATH=$ORIGINAL_PATH echo "Restored original PATH" python --version }
...for Windows, involves mucking with %PATH%
If you use this approach...
-
edit your
~/.bash_profile
to includesource ~/.bashrc
. -
after opening a new shell, to use
conda
, use cmd:$ use_conda
-
to switch back to your original
PATH
, use cmd:$ use_original
personally, I keep .bashrc
mostly empty and use project-specific config.sh
files that I source when needed, keep those under version control!
Pieces of the machinery:
- cmds:
$ conda help
- envs:
/home/juser/anaconda/envs/<tree-of-links>
- pkgs:
/home/juser/anaconda/pkgs/*.tar.bz2
- path: shell variable
$PATH
andsource
command
Most common modifications to an existing env:
- add pkg:
conda install pkg
- update pkg:
conda update pkg
- remove pkg:
conda remove pkg
-
Activate an env to install into it...
# Linux/OSX $ source activate py27 $ conda install numpy scipy
-
Alternatively, from any conda env...
$ conda install -n py27 numpy scipy
...again, for Windows, drop word "source"
-
Update individual packages...
$ conda update -n py27 numpy scipy
-
Update all pkgs while maintaining pkg-to-pkg compatibility...
$ conda update -n py27 --all
-
Update
conda
itself inroot
env before doing anything...$ conda update conda
-
To remove one or more pkgs:
$ conda remove -n py27 numpy scipy
-
Removing pkgs can leave dependency detritus.
-
Often better to remove entire env.
-
Create a new env that only includes what you need.
-
To delete an env, remove all packages from it.
$ conda remove -n py27 --all
-
Creating and deleting entire envs is easy and fast.
-
When in doubt, delete and create a new one...
-
"It's the only way to be sure".
-
You can
export
a "manifest", listing all pkgs, versions -
Conda can recreate an env from the
environment.yml
! -
To
export
your conda environment:$ conda env export -n py34 > environment.yml
-
To recreate the env: (assumes
environment.yml
)$ conda env create
-
To recreate an env from a non-default file name:
$ conda env create -f analysis_2017.yml
-
Delete the anaconda/miniconda directory tree:
$ rm -rf $HOME/anaconda
...or:
$ rm -rf $HOME/miniconda3
Forgot where you installed conda? Just ask the shell:
$ which python
- Remove lines from your shell config files
- review both
$HOME/.bash_profile
or$HOME/.bashrc
- remove
PATH
changes by conda/Anaconda/MiniConda:# added by Anaconda3 4.2.0 installer export PATH="/Users/juser/anaconda/bin:$PATH"
- remove any shell functions you added like
use_conda
- review both