Skip to content

Instantly share code, notes, and snippets.

@chriswayg
Last active July 17, 2020 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswayg/4bcc14a1dfd5e5479d604a06cd620b0b to your computer and use it in GitHub Desktop.
Save chriswayg/4bcc14a1dfd5e5479d604a06cd620b0b to your computer and use it in GitHub Desktop.
Install conda Python on macOS in 30 seconds - Oneliner that downloads, installs and activates Miniconda Python 2.7 or 3.x

Install conda Python on macOS in 30 seconds

Oneliner that downloads, installs and activates Miniconda Python 2.7 or 3.x

  • at 50 Mbps on a recent Mac, the 50 MB download including install takes about 30 seconds ;-)

Quick Miniconda install

  • Usage: copy one of the two following lines and paste it into your terminal
Python 3.x
v=3; f=Miniconda${v}-latest-MacOSX-x86_64.sh; cd $TMPDIR; { curl -LfOsS https://repo.anaconda.com/miniconda/$f ; cd -; } && bash $TMPDIR/$f -b && echo ". ~/miniconda${v}/etc/profile.d/conda.sh" >> ~/.bash_profile; . ~/miniconda${v}/bin/activate
Python 2.7
v=2; f=Miniconda${v}-latest-MacOSX-x86_64.sh; cd $TMPDIR; { curl -LfOsS https://repo.anaconda.com/miniconda/$f ; cd -; } && bash $TMPDIR/$f -b && echo ". ~/miniconda${v}/etc/profile.d/conda.sh" >> ~/.bash_profile; . ~/miniconda${v}/bin/activate

Miniconda quickstart

  • To activate the (base) virt. env. manually in another shell use conda activate
  • To create another virtual environment and activate / list / deactivate:
conda create --name project1
conda activate project1
conda info --envs
...
conda deactivate

Remove in 5 seconds

conda deactivate >/dev/null 2>&1; rm -rf ~/miniconda{2,3}; sed -i.bak '/. ~\/miniconda*/d' ~/.bash_profile

The Oneliner split-up with detailed comments

# Python version 2 or 3
v=3;

# Download latest miniconda 64 bit
# https://docs.conda.io/en/latest/miniconda.html
f=Miniconda${v}-latest-MacOSX-x86_64.sh;

# Use a temporary dir such as: /var/folders/9l/wwt.../T/
cd $TMPDIR;

# Use Curl as macOS does not come with wget
# Options: curl --location --fail --remote-name --silent --show-error
# switch back to previous dir
{ curl -LfOsS https://repo.anaconda.com/miniconda/$f ; cd -; } &&

# Use the miniconda installer to install in silent mode
bash $TMPDIR/$f -b &&

# Add miniconda to the PATH, while not enabling auto-activation in every shell
echo ". ~/miniconda${v}/etc/profile.d/conda.sh" >> ~/.bash_profile;

# Activate a virtual environment in the current shell
. ~/miniconda${v}/bin/activate


Regualar Miniconda install

The only difference is, that this will add a much bigger section to the .bash_profile, which by default auto-activates the base environment in every shell, unless you disable that with conda config --set auto_activate_base false, as added below.

Python 3.x
v=3; f=Miniconda${v}-latest-MacOSX-x86_64.sh; cd $TMPDIR; { curl -LfOsS https://repo.anaconda.com/miniconda/$f ; cd -; } && bash $TMPDIR/$f -b && . ~/miniconda${v}/bin/activate && conda init && conda config --set auto_activate_base false
Python 2.7
v=2; f=Miniconda${v}-latest-MacOSX-x86_64.sh; cd $TMPDIR; { curl -LfOsS https://repo.anaconda.com/miniconda/$f ; cd -; } && bash $TMPDIR/$f -b && . ~/miniconda${v}/bin/activate && conda init && conda config --set auto_activate_base false

Older versions of macOS or OS X

  • the latest version of Miniconda Python may not work on older OS versions, substitute the following:
  • Mavericks 10.9.5 use Miniconda3-4.5.11-MacOSX-x86_64.sh (updates to conda version : 4.8.3, python version : 3.7.2.final.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment